我从 Android 客户端连接到我的网络服务时遇到问题。在我的 MainActivity 类中,程序在以下行崩溃:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
问题绝对不是方法名称,而是名称空间的问题,但我不知道出了什么问题。
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";
主要活动:
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();
}
}
我的 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>
Web 服务中的我的 GameWS.java:
package pl.webcentral.game;
import java.util.HashMap;
@WebService(targetNamespace = "http://game.webcentral.pl/", portName = "GameWS", serviceName = "GameWSService")
public class GameWS {
// Further code
}
我究竟做错了什么?我真的什么都试过了。Web 服务本身工作正常。
更新的 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