With a lot of digging that I learnt that it is not easy to implement KSOAP2 Web service client in Android, which I am new to.
I have implemented this code with lots of resources I gathered online but I get this error message in LogCat :
- Code: Select all
09-17 19:31:45.710: WARN/System.err(711): java.net.ConnectException: /127.0.0.1:8081 - Connection refused
09-17 19:31:45.720: WARN/System.err(711): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:237)
09-17 19:31:45.729: WARN/System.err(711): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:199)
09-17 19:31:45.729: WARN/System.err(711): at java.net.Socket.startupSocket(Socket.java:734)
09-17 19:31:45.729: WARN/System.err(711): at java.net.Socket.<init>(Socket.java:190)
09-17 19:31:45.729: WARN/System.err(711): at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
09-17 19:31:45.729: WARN/System.err(711): at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
09-17 19:31:45.729: WARN/System.err(711): at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
09-17 19:31:45.739: WARN/System.err(711): at android.KSOAP.WEBCLIENT.AndroidServiceConnection.connect(AndroidServiceConnection.java:40)
09-17 19:31:45.739: WARN/System.err(711): at android.KSOAP.WEBCLIENT.AndroidHttpTransport.call(AndroidHttpTransport.java:39)
09-17 19:31:45.739: WARN/System.err(711): at android.KSOAP.WEBCLIENT.CallServ.mymethod(CallServ.java:34)
09-17 19:31:45.739: WARN/System.err(711): at android.KSOAP.WEBCLIENT.CallServ.onCreate(CallServ.java:20)
09-17 19:31:45.739: WARN/System.err(711): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
09-17 19:31:45.739: WARN/System.err(711): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
09-17 19:31:45.739: WARN/System.err(711): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
09-17 19:31:45.749: WARN/System.err(711): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
09-17 19:31:45.749: WARN/System.err(711): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
09-17 19:31:45.749: WARN/System.err(711): at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 19:31:45.749: WARN/System.err(711): at android.os.Looper.loop(Looper.java:123)
09-17 19:31:45.749: WARN/System.err(711): at android.app.ActivityThread.main(ActivityThread.java:4203)
09-17 19:31:45.749: WARN/System.err(711): at java.lang.reflect.Method.invokeNative(Native Method)
09-17 19:31:45.749: WARN/System.err(711): at java.lang.reflect.Method.invoke(Method.java:521)
09-17 19:31:45.759: WARN/System.err(711): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
09-17 19:31:45.759: WARN/System.err(711): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
09-17 19:31:45.759: WARN/System.err(711): at dalvik.system.NativeStart.main(Native Method)
I think there is something wrong with the way i am invoking the webservice so below i have attached the invoking code and my WSDL File
java
Using java Syntax Highlighting
- import org.ksoap2.SoapEnvelope;
- import org.ksoap2.serialization.SoapObject;
- import org.ksoap2.serialization.SoapSerializationEnvelope;
- import android.app.Activity;
- import android.os.Bundle;
- public class CallServ extends Activity {
- /** Called when the activity is first created. */
- private static final String SOAP_ACTION = "getTotal";
- private static final String METHOD_NAME = "getTotal";
- private static final String NAMESPACE = "http://SERV/";
- private static final String URL = "http://127.0.0.1:8081/ADDWEBSERVICEwar/NewWebServiceService?xsd=1";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mymethod();
- setContentView(R.layout.main);
- }
- public static String mymethod() {
- SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
- request.addProperty("i", "4");
- request.addProperty("j", "4");
- SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
- envelope.setOutputSoapObject(request);
- AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
- String stest="test**";
- try {
- androidHttpTransport.call(SOAP_ACTION, envelope);
- Object result = envelope.getResponse();
- stest=result.toString();
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println("$$$$$$"+e.toString());
- }
- System.out.println("******************"+stest);
- return stest;
- }
- }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
WSDL
Using xml Syntax Highlighting
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-417-SNAPSHOT. -->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-417-SNAPSHOT. -->
- <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://SERV/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://SERV/" name="NewWebServiceService">
- <types>
- <xsd:schema>
- <xsd:import namespace="http://SERV/" schemaLocation="http://localhost:8081/ADDWEBSERVICE-war/NewWebServiceService?xsd=1"/>
- </xsd:schema>
- </types>
- <message name="getTotal">
- <part name="parameters" element="tns:getTotal"/>
- </message>
- <message name="getTotalResponse">
- <part name="parameters" element="tns:getTotalResponse"/>
- </message>
- <message name="UpdateUser">
- <part name="parameters" element="tns:UpdateUser"/>
- </message>
- <message name="UpdateUserResponse">
- <part name="parameters" element="tns:UpdateUserResponse"/>
- </message>
- <message name="Loging">
- <part name="parameters" element="tns:Loging"/>
- </message>
- <message name="LogingResponse">
- <part name="parameters" element="tns:LogingResponse"/>
- </message>
- <portType name="NewWebService">
- <operation name="getTotal">
- <input message="tns:getTotal"/>
- <output message="tns:getTotalResponse"/>
- </operation>
- <operation name="UpdateUser">
- <input message="tns:UpdateUser"/>
- <output message="tns:UpdateUserResponse"/>
- </operation>
- <operation name="Loging">
- <input message="tns:Loging"/>
- <output message="tns:LogingResponse"/>
- </operation>
- </portType>
- <binding name="NewWebServicePortBinding" type="tns:NewWebService">
- <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
- <operation name="getTotal">
- <soap:operation soapAction=""/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- <operation name="UpdateUser">
- <soap:operation soapAction=""/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- <operation name="Loging">
- <soap:operation soapAction=""/>
- <input>
- <soap:body use="literal"/>
- </input>
- <output>
- <soap:body use="literal"/>
- </output>
- </operation>
- </binding>
- <service name="NewWebServiceService">
- <port name="NewWebServicePort" binding="tns:NewWebServicePortBinding">
- <soap:address location="http://localhost:8081/ADDWEBSERVICE-war/NewWebServiceService"/>
- </port>
- </service>
- </definitions>
Parsed in 0.013 seconds, using GeSHi 1.0.8.4
the Webservice is running under glassfish server. I have a felling that my values are wrong in this part which may cause the problem. Please compare the WSDL file and my code to see where i am going wrong.
Using java Syntax Highlighting
- private static final String SOAP_ACTION = "getTotal";
- private static final String METHOD_NAME = "getTotal";
- private static final String NAMESPACE = "http://SERV/";
- private static final String URL = "http://127.0.0.1:8081/ADDWEBSERVICEwar/NewWebServiceService?xsd=1";
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Thanks in advance

