LkDev
LkDev

Reputation: 221

How to call JAX-WS in GWT client interface?

I am developing project on GWT(Google Web Toolkit) and I need to call web service(JAX-WS). But problem is I don't know how to call the web services from GWT so I need to know how to access that JAX-WS with in GWT client side ? I'm developing my project on eclips and my service is run on glassfish server.

Please be kind enough to give some basic instructions to solve this problem.

Upvotes: 2

Views: 677

Answers (1)

The normal way to call external non-gwt ws is via the RequestBuilder class, although this is not difficult it could be tedious when you need to prepare several calls in your application.

I recommend you to take a look to gwtquery aka gquery which have an Ajax class which allows call to ws in a very easy manner. Take a look to the documentation

This could be an example of a jax-ws serving json responses

  @BindingType(JSONBindingID.JSON_BINDING)
  public class MyService {
    public Book get(@WebParam(name="id") int id) {
      Book b = new Book();
      b.id = id;
      return b;
    }

    public static final class Book {
      public int id = 1;
      public String title = "Java";
    }
  }

And this could be the client call in client side

 import static com.google.gwt.query.client.GQuery.*;
 [...]

  post( //GQuery post static method (you have get, ajax, getJSONP, etc)
      "http://url_to_the_jax-ws.server/MyService", 
      $$("{get:{id:5}}"),                     // GQuery json parses the parameters
      new Function(){                         // Callback
        public void f() {
          Properties p = getDataProperties(); // JSON response
          alert("success " + p.get("title"));
        }
      }
  );

Upvotes: 2

Related Questions