Friday, September 30, 2011

Android Web Service Client


Using AndroidSOAP is a very easy way to call a SOAP service, because it is based on JAX-WS interfaces. You can use all interfaces that the 'wsimport' generates from the WSDL. Short example:
 /**
  * Creates a request, it is a JAX-WS generated class
  */
 ListSkinPacksRequest request = new ListSkinPacksRequest();
 /**
  * Put it into a 'request' map
  */ 
 Map<String, Object> parameters = new HashMap<String, Object>();
 parameters.put("request", request);

 /**
  * Creates an envelope with namespace and creates a body with operation name 'listSkinPacks'
  */
 Envelope envelope = new SimpleEnvelope("http://skinpack.pop.javaforum.hu/");
 envelope.setHeader(new SimpleHeader());
 envelope.setBody(new SimpleBody("listSkinPacks", parameters));

 /**
  * Creates a transport (HTTP or HTTPS) with an optional username/password
  */
 Transport transport = new HttpTransport("http://services.power.of.planets.hu/PoP-SkinPack-remote/listSkinPacks",
                                         "androidsoap.demo@javaforum.hu", "demopassword");
 /**
  * Call a service, the result arrives into the JAX-WS class
  */
 ListSkinPacksResponse response = transport.call(envelope, "return", ListSkinPacksResponse.class);

 /**
  * You can use the result
  */
 for (SkinPackMetadata metadata : response.getReturn().getSkinPacksList())
 {
   String fileName = metadata.getFileName();
   String name = metadata.getName();
 }
Can you see? The lists are lists, the classes are classes, the values are in the properties, just like in the JAX-WX client... 

Where?

No comments:

Post a Comment