2

I got a problem connecting to my webservice from an Android client. In my MainActivity class the program crashes at the line:

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

The problem is definetely not with the method name, it's rather something about the namespace but I don't know what is wrong.

GameAndroidUtil:

private static final String NAMESPACE = "http://game.webcentral.pl/";
private static final String SOAP_ACTION = "";
private static final String WSDL_URL = "http://localhost:8080/ReversiGameWS/services/GameWS?wsdl";

MainActivity:

protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            GameAndroidUtil.testGameWS();
        } catch (SoapFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

My GameWS.wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://game.webcentral.pl" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://game.webcentral.pl" xmlns:intf="http://game.webcentral.pl" xmlns:tns1="http://data.game.webcentral.pl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://game.webcentral.pl" xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://data.game.webcentral.pl"/>
   <element name="addMove">
    <complexType>
     <sequence>
      <element name="sessionId" type="xsd:string"/>
      <element name="move" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
   <element name="addMoveResponse">
    <complexType/>
   </element>
   <element name="fault" type="tns1:GameException"/>
   <element name="login">
    <complexType>
     <sequence>
      <element name="userName" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="loginResponse">
    <complexType>
     <sequence>
      <element name="loginReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="getGameStatus">
    <complexType>
     <sequence>
      <element name="sessionId" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="getGameStatusResponse">
    <complexType>
     <sequence>
      <element name="getGameStatusReturn" type="tns1:GameStatus"/>
     </sequence>
    </complexType>
   </element>
  </schema>
  <schema elementFormDefault="qualified" targetNamespace="http://data.game.webcentral.pl" xmlns="http://www.w3.org/2001/XMLSchema">
   <complexType name="GameException">
    <sequence/>
   </complexType>
   <complexType name="GameStatus">
    <sequence>
     <element name="lastMove" nillable="true" type="xsd:int"/>
     <element name="yourMove" type="xsd:boolean"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>

   <wsdl:message name="loginResponse">

      <wsdl:part element="impl:loginResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="loginRequest">

      <wsdl:part element="impl:login" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="GameException">

      <wsdl:part element="impl:fault" name="fault">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="addMoveRequest">

      <wsdl:part element="impl:addMove" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="addMoveResponse">

      <wsdl:part element="impl:addMoveResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getGameStatusRequest">

      <wsdl:part element="impl:getGameStatus" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="getGameStatusResponse">

      <wsdl:part element="impl:getGameStatusResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="GameWS">

      <wsdl:operation name="addMove">

         <wsdl:input message="impl:addMoveRequest" name="addMoveRequest">

       </wsdl:input>

         <wsdl:output message="impl:addMoveResponse" name="addMoveResponse">

       </wsdl:output>

         <wsdl:fault message="impl:GameException" name="GameException">

       </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="login">

         <wsdl:input message="impl:loginRequest" name="loginRequest">

       </wsdl:input>

         <wsdl:output message="impl:loginResponse" name="loginResponse">

       </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="getGameStatus">

         <wsdl:input message="impl:getGameStatusRequest" name="getGameStatusRequest">

       </wsdl:input>

         <wsdl:output message="impl:getGameStatusResponse" name="getGameStatusResponse">

       </wsdl:output>

         <wsdl:fault message="impl:GameException" name="GameException">

       </wsdl:fault>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="GameWSSoapBinding" type="impl:GameWS">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="addMove">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="addMoveRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="addMoveResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="GameException">

            <wsdlsoap:fault name="GameException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="login">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="loginRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="loginResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

      <wsdl:operation name="getGameStatus">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="getGameStatusRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="getGameStatusResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="GameException">

            <wsdlsoap:fault name="GameException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="GameWSService">

      <wsdl:port binding="impl:GameWSSoapBinding" name="GameWS">

         <wsdlsoap:address location="http://localhost:8080/ReversiGameWS/services/GameWS"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

My GameWS.java from the Web service:

package pl.webcentral.game;

import java.util.HashMap;

@WebService(targetNamespace = "http://game.webcentral.pl/", portName = "GameWS",        serviceName = "GameWSService")
public class GameWS {

// Further code

}

What am I doing wrong? I've really tried everything. The web service itself is working correctly.

Updated LogCat:

    01-12 16:54:27.930: E/AndroidRuntime(1070): FATAL EXCEPTION: main
01-12 16:54:27.930: E/AndroidRuntime(1070): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.webcentral.androidclient1/pl.webcentral.androidclient1.MainActivity}: java.lang.RuntimeException: Unexpected exception
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.os.Looper.loop(Looper.java:137)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread.main(ActivityThread.java:4745)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at java.lang.reflect.Method.invokeNative(Native Method)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at java.lang.reflect.Method.invoke(Method.java:511)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at dalvik.system.NativeStart.main(Native Method)
01-12 16:54:27.930: E/AndroidRuntime(1070): Caused by: java.lang.RuntimeException: Unexpected exception
01-12 16:54:27.930: E/AndroidRuntime(1070):     at pl.webcentral.androidclient1.GameAndroidUtil.callGameLogin(GameAndroidUtil.java:76)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at pl.webcentral.androidclient1.GameAndroidUtil.testGameWS(GameAndroidUtil.java:18)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at pl.webcentral.androidclient1.MainActivity.onCreate(MainActivity.java:24)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.Activity.performCreate(Activity.java:5008)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
01-12 16:54:27.930: E/AndroidRuntime(1070):     ... 11 more
01-12 16:54:27.930: E/AndroidRuntime(1070): Caused by: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) after 20000ms: isConnected failed: ECONNREFUSED (Connection refused)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.io.IoBridge.isConnected(IoBridge.java:224)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.io.IoBridge.connect(IoBridge.java:112)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at java.net.Socket.connect(Socket.java:842)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:120)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:176)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at pl.webcentral.androidclient1.GameAndroidUtil.callGameLogin(GameAndroidUtil.java:69)
01-12 16:54:27.930: E/AndroidRuntime(1070):     ... 16 more
01-12 16:54:27.930: E/AndroidRuntime(1070): Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
01-12 16:54:27.930: E/AndroidRuntime(1070):     at libcore.io.IoBridge.isConnected(IoBridge.java:208)
01-12 16:54:27.930: E/AndroidRuntime(1070):     ... 36 more
01-12 16:54:32.910: I/Process(1070): Sending signal. PID: 1070 SIG: 9
user208030
  • 145
  • 2
  • 9

3 Answers3

6

You are trying to connect to the web-service by specifying localhost:8080 as the address of the system hosting the service. The Android emulator runs inside a Virtual Machine (QEMU). Hence, localhost:8080 would be the emulator's own loop back address, and not that of the system.

So, you can either go to CommandPrompt in your Windows to get the IP address of your system or just use http://10.0.2.2:8080/... instead of using localhost.

private static final String WSDL_URL = "http://10.0.2.2:8080/ReversiGameWS/services/GameWS?wsdl";
Swayam
  • 16,294
  • 14
  • 64
  • 102
1

The problem is very likely that you are trying to perform Web calls on the UI thread.

Check your logcat, and you will likely see this error called out.

You need to not make long running calls (like web service calls) no the UI thread, and are required to move them off the thread using AsyncTasks.

If this is not the case, you will need to include your logcat output so we can learn more.

Booger
  • 18,579
  • 7
  • 55
  • 72
0

java.lang.VerifyError can be the result when you have compiled against a different library than you are using at runtime.

For example, this happened to me when trying to run a program that was compiled against Xerces 1, but Xerces 2 was found on the classpath. The required classes (in org.apache.* namespace) were found at runtime, so ClassNotFoundException was not the result. There had been changes to the classes and methods, so that the method signatures found at runtime did not match what was there at compile-time.

Normally, the compiler will flag problems where method signatures do not match. The DVM will verify the bytecode again when the class is loaded, and throws VerifyError when the bytecode is trying to do something that should not be allowed - Like calling a method that returns String and then stores that return value in a field that holds a List.

Please ensure that you are using the correct version of any jar or library at compile time.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • Thank you for the response! I am not sure whether I understood what you meant correctly. How can I ensure that the correct version of jar is used at compile time? – user208030 Jan 12 '13 at 15:37
  • I can't say unless I know which libraries you're using. – Raghav Sood Jan 12 '13 at 15:38
  • Ok, I did it, it helped. Now i got a runtime exception... 01-12 16:54:27.930: E/AndroidRuntime(1070): FATAL EXCEPTION: main 01-12 16:54:27.930: E/AndroidRuntime(1070): java.lang.RuntimeException: Unable to start activity ComponentInfo{pl.webcentral.androidclient1/pl.webcentral.androidclient1.MainActivity}: java.lang.RuntimeException: Unexpected exception 01-12 16:54:27.930: E/AndroidRuntime(1070): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) – user208030 Jan 12 '13 at 15:57