views:

296

answers:

3

How to create an Android application with WS-* services connections?

Where to get information for beginners - it should contain video tutorials and explanation what types of bindings are not supported.

+1  A: 

I don't believe Android has any in-built WS-* support; it has Java networking, the Apache HTTP client, JSON and XML parsers, but no native WS-* libraries.

Presumably you don't want to write your own WS libraries on top of Android. So because Android uses the Java language for development, you should be able to include whatever relevant libraries you use for non-mobile development. e.g. the Apache WS libraries.

Christopher
A: 

It might be easier to design a web service using WS-* and then expose a REST front end to it, and just use simple java.net.URL and java.net.URLConnection classes to communicate to your frontend.

Chad Okere
+2  A: 

The simple and basic idea is to establish a connection to the Web Service URL and post the XML data to that URL. The code below assumes the Web Service URL is http://www.example.com/example.asmx and the method you want to call is WebServiceMethod1 which accepts one string parameter. The return string is the response from the Web Service, you have to parse the XML to get the data.

public static String callWebServiceMethod(String email){
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.example.com/example.asmx");
String  webServiceXml = "";
String  response = "";

try
{
 webServiceXml += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
 webServiceXml += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;";
 webServiceXml += "<soap:Header>";
 webServiceXml += "<AuthHeader xmlns=\"http://www.example.com/\"&gt;";
 webServiceXml += "</AuthHeader>";
 webServiceXml += "</soap:Header>";
 webServiceXml += "<soap:Body>";
 webServiceXml += "<WebServiceMethod1 xmlns=\"http://www.example.com/\"&gt;";
 webServiceXml += "<emailId>" + email + "</emailId>";
 webServiceXml += "</WebServiceMethod1>";
 webServiceXml += "</soap:Body>";
 webServiceXml += "</soap:Envelope>";

 httpPost.setHeader("content-type","text/xml; charset=utf-8");
 httpPost.setHeader("SOAPAction","http://www.example.com/WebServiceMethod1");

 httpPost.setEntity(new StringEntity(webServiceXml));

 HttpResponse httpResponse = httpClient.execute(httpPost);

 response = EntityUtils.toString(httpResponse.getEntity());
}
catch(Exception ex)
{
 Log.i("error", ex.getMessage());
}

return response;

}

Krishnaraj Varma