Problem With KSOAP2 Webservice

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Problem With KSOAP2 Webservice

Postby rtn » Thu Sep 17, 2009 7:44 pm

Hi Guys,

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

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  import org.ksoap2.SoapEnvelope;
  2.  
  3. import org.ksoap2.serialization.SoapObject;
  4.  
  5. import org.ksoap2.serialization.SoapSerializationEnvelope;
  6.  
  7.  
  8.  
  9. import android.app.Activity;
  10.  
  11. import android.os.Bundle;
  12.  
  13.  
  14.  
  15. public class CallServ extends Activity {
  16.  
  17.     /** Called when the activity is first created. */
  18.  
  19.        
  20.  
  21.         private static final String SOAP_ACTION = "getTotal";
  22.  
  23.         private static final String METHOD_NAME = "getTotal";
  24.  
  25.         private static final String NAMESPACE = "http://SERV/";
  26.  
  27.         private static final String URL = "http://127.0.0.1:8081/ADDWEBSERVICEwar/NewWebServiceService?xsd=1";
  28.  
  29.     @Override
  30.  
  31.     public void onCreate(Bundle savedInstanceState) {
  32.  
  33.         super.onCreate(savedInstanceState);
  34.  
  35.        mymethod();
  36.  
  37.         setContentView(R.layout.main);
  38.  
  39.     }
  40.  
  41.    
  42.  
  43.     public static String mymethod() {
  44.  
  45.          SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  46.  
  47.          request.addProperty("i", "4");
  48.  
  49.          request.addProperty("j", "4");
  50.  
  51.  
  52.  
  53.          SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  54.  
  55.          envelope.setOutputSoapObject(request);
  56.  
  57.          AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
  58.  
  59.          String stest="test**";
  60.  
  61.          try {
  62.  
  63.           androidHttpTransport.call(SOAP_ACTION, envelope);
  64.  
  65.           Object result = envelope.getResponse();
  66.  
  67.           stest=result.toString();
  68.  
  69.          } catch (Exception e) {
  70.  
  71.           e.printStackTrace();
  72.  
  73.           System.out.println("$$$$$$"+e.toString());
  74.  
  75.          }
  76.  
  77.        
  78.  
  79.         System.out.println("******************"+stest);
  80.  
  81.           return stest;
  82.  
  83.         }
  84.  
  85.    
  86.  
  87.    
  88.  
  89.    
  90.  
  91. }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4



WSDL

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <!-- 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. -->
  2.  
  3. <!-- 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. -->
  4.  
  5. <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">
  6.  
  7. <types>
  8.  
  9. <xsd:schema>
  10.  
  11. <xsd:import namespace="http://SERV/" schemaLocation="http://localhost:8081/ADDWEBSERVICE-war/NewWebServiceService?xsd=1"/>
  12.  
  13. </xsd:schema>
  14.  
  15. </types>
  16.  
  17. <message name="getTotal">
  18.  
  19. <part name="parameters" element="tns:getTotal"/>
  20.  
  21. </message>
  22.  
  23. <message name="getTotalResponse">
  24.  
  25. <part name="parameters" element="tns:getTotalResponse"/>
  26.  
  27. </message>
  28.  
  29. <message name="UpdateUser">
  30.  
  31. <part name="parameters" element="tns:UpdateUser"/>
  32.  
  33. </message>
  34.  
  35. <message name="UpdateUserResponse">
  36.  
  37. <part name="parameters" element="tns:UpdateUserResponse"/>
  38.  
  39. </message>
  40.  
  41. <message name="Loging">
  42.  
  43. <part name="parameters" element="tns:Loging"/>
  44.  
  45. </message>
  46.  
  47. <message name="LogingResponse">
  48.  
  49. <part name="parameters" element="tns:LogingResponse"/>
  50.  
  51. </message>
  52.  
  53. <portType name="NewWebService">
  54.  
  55. <operation name="getTotal">
  56.  
  57. <input message="tns:getTotal"/>
  58.  
  59. <output message="tns:getTotalResponse"/>
  60.  
  61. </operation>
  62.  
  63. <operation name="UpdateUser">
  64.  
  65. <input message="tns:UpdateUser"/>
  66.  
  67. <output message="tns:UpdateUserResponse"/>
  68.  
  69. </operation>
  70.  
  71. <operation name="Loging">
  72.  
  73. <input message="tns:Loging"/>
  74.  
  75. <output message="tns:LogingResponse"/>
  76.  
  77. </operation>
  78.  
  79. </portType>
  80.  
  81. <binding name="NewWebServicePortBinding" type="tns:NewWebService">
  82.  
  83. <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
  84.  
  85. <operation name="getTotal">
  86.  
  87. <soap:operation soapAction=""/>
  88.  
  89. <input>
  90.  
  91. <soap:body use="literal"/>
  92.  
  93. </input>
  94.  
  95. <output>
  96.  
  97. <soap:body use="literal"/>
  98.  
  99. </output>
  100.  
  101. </operation>
  102.  
  103. <operation name="UpdateUser">
  104.  
  105. <soap:operation soapAction=""/>
  106.  
  107. <input>
  108.  
  109. <soap:body use="literal"/>
  110.  
  111. </input>
  112.  
  113. <output>
  114.  
  115. <soap:body use="literal"/>
  116.  
  117. </output>
  118.  
  119. </operation>
  120.  
  121. <operation name="Loging">
  122.  
  123. <soap:operation soapAction=""/>
  124.  
  125. <input>
  126.  
  127. <soap:body use="literal"/>
  128.  
  129. </input>
  130.  
  131. <output>
  132.  
  133. <soap:body use="literal"/>
  134.  
  135. </output>
  136.  
  137. </operation>
  138.  
  139. </binding>
  140.  
  141. <service name="NewWebServiceService">
  142.  
  143. <port name="NewWebServicePort" binding="tns:NewWebServicePortBinding">
  144.  
  145. <soap:address location="http://localhost:8081/ADDWEBSERVICE-war/NewWebServiceService"/>
  146.  
  147. </port>
  148.  
  149. </service>
  150.  
  151. </definitions>
Parsed in 0.014 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.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3. private static final String SOAP_ACTION = "getTotal";
  4.  
  5.         private static final String METHOD_NAME = "getTotal";
  6.  
  7.         private static final String NAMESPACE = "http://SERV/";
  8.  
  9.         private static final String URL = "http://127.0.0.1:8081/ADDWEBSERVICEwar/NewWebServiceService?xsd=1";
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
[i]

Thanks in advance
rtn
Freshman
Freshman
 
Posts: 5
Joined: Thu Sep 17, 2009 7:24 pm

Top

Postby rtn » Sun Sep 20, 2009 6:30 pm

Don't worry guys, i have solved the problem myself
rtn
Freshman
Freshman
 
Posts: 5
Joined: Thu Sep 17, 2009 7:24 pm

Don't do that.

Postby coleman » Thu Oct 01, 2009 8:02 pm

If you find the solution, post the answer. Or kill the whole thread. It just makes searching for an answer harder to find.
Steve Coleman
coleman
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Oct 01, 2009 7:59 pm
Location: Houston

Postby herge » Tue Oct 06, 2009 12:17 pm

probably he changed the remote ipadress to 10.0.2.2 (read manual http://developer.android.com/guide/deve ... networking ). The emulator uses 127.0.0.1 as it's own local adress and hence it can't connect to the host computer.

Best Regards
Ulf
------------------------------------
http://blogherge.blogspot.com/
herge
Freshman
Freshman
 
Posts: 5
Joined: Mon Oct 05, 2009 7:03 am
Location: Sweden

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 8 guests