开发者

What are options for GWT to C++ communication?

I am looking for GWT to C++ communication solution. Currently I am trying to figure out how to run WSDL in GWT, but actually, have absolutely no experience in WSDL, and only little in GWT.

So, my question is about feasibility of working with WSDL in GWT (and how?) and other approaches would also be interesting if开发者_JAVA百科 exist.

I am trying to avoid coding Java on the server and coding JavaScript on client.


GWT Side:

RequestBuilder and com.google.gwt.json.client.JSONObject for quick and really not that dirty marshaling api.

Overlay types require you to know your data configuration at compile time. With JSONObject (and it's JSONValue's), you can treat it like a slightly unwieldy key/value map.

Set your RequestBuilder to POST and serialize your payload by pushing it into a JSONObject and calling toJSON();

C++ side.. Find a favorite JSON library (may I suggest from the fine choices at http://www.json.org/)

(You'll have to build a method dispatching scheme, but if your app is simple, just use some simple if ()'s)

Send back a response with mime-type of text/javascript;charset=UTF-8.

Back in your GWT code, you read back the results using something like so:

  if (Response.SC_OK == response.getStatusCode()) {
     try {
        String txtResponse = response.getText();
        if (txtResponse != null && txtResponse.length() > 0) {
           JSONObject result = (JSONObject)JSONParser.parse(testResponse);
           //Do something useful...
        }
     } catch (......)

Now you can talk back and forth with no magic. (And goodness know, no WDSL!!!)


Thrift may be the best solution for you. A specific portage for GWT is available at : http://code.google.com/p/thrift-gwt/ .


You can expose a JSON-based API on your server and use GWT's RequestBuilder and JavaScript Overlay Types to consume it in the client.

You could also use an XML-based API, but JSON will be easiest because of overlay types.


I found Thrift is almost the only choice that includes code-generation-based data-binding solution with RPC support that works on C++ side (original Apache Thrift compiler) and GWT side (gwt-rpc-plus solution).

That is a coincidence, but Thrift is actually a good JSON data-binding solution.

The only problem I see with Thrift (and it's rather inconvenience) - it doesn't support structure polymorphism, which is Ok for JavaScript (Thrift supports it), but bad for real object-oriented languages like C++ and Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜