views:

148

answers:

3

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 exist.

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

A: 

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.

Jason Hall
+1  A: 

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!!!)

Adam Malter
JSON, probably, would be a good choice for Java/JavaScript solution, but I prefer data binding-style solution and haven't yet found one for JSON. That's why I am trying to work with WSDL - generate data bindings for C++, generate data bindings for Java using Axis2, compile Java part for GWT.Are there any other data binding solutions available for C++/Java/GWT?
A: 

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.