I have a HelloWorld web service deployed on a server. Now im trying to talk to the server. How do i do a SOAP request from within a Java application ?
Here is the XML envelope (request):
POST /AndroidSampleApp/Test.asmx HTTP/1.1
Host: (host)
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloWorld"
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/">
<username>string</username>
<password>string</password>
</HelloWorld>
</soap:Body>
</soap:Envelope>
Here is the XML envelope (request):
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<HelloWorldResponse xmlns="http://tempuri.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>
How do i call this webservice from a java program and what packages do i need to import. Thanks!
Note: This is for an android application
You can use the ksoap2 library to easily make your soap webservie calls.
Ksoap is relatively easy to use, but I’ve run into some performance issues with connectivity on some networks using it.
Instead, I’ve been using HttpUrlConnection (or AndroidHttpClient, depending on the OS version). See this post for more information. I use these in combination with any of the XML parsers and builders available on Android.
Hope this helps!