我正在使用以下代码进行使用KSOAP的Web服务调用。
private static final String SOAP_ACTION = "http://www.tempuri.org/GetAuthenticateUser";
private static final String METHOD_NAME = "GetAuthenticateUser";
private static final String NAMESPACE = "http://www.tempuri.org/";
private static final String URL = "http://stage.mysite.com/FinancialSnapshotService/Service.asmx?WSDL";
// I have tried http://stage.mysite.com/FinancialSnapshotService/Service.asmx also
public void getResults() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("vstrUserID", "vk@gmail.com");
request.addProperty("vstrPassword", "password");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
HttpTransportSE aht = new HttpTransportSE(URL);
try {
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject result = (SoapObject) soapEnvelope.getResponse();
Log.d("WS", String.valueOf(result));
} catch (Exception e) {
e.printStackTrace();
}
}
虽然Web服务非常好(因为它适用于Iphone应用程序),但我收到错误:
05-03 16:47:49.427: WARN/ActivityManager(1194): Activity pause timeout for HistoryRecord{45cc0980 ksoap2app.main/.Ksoap2App}
05-03 16:47:49.821: WARN/System.err(4055): SoapFault - faultcode: 'soap:Client' faultstring: 'Server did not recognize the value of HTTP Header SOAPAction: http://www.tempuri.org/GetAuthenticateUser.' faultactor: 'null' detail: org.kxml2.kdom.Node@45927830
05-03 16:47:49.831: WARN/System.err(4055): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:112)
05-03 16:47:49.831: WARN/System.err(4055): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137)
05-03 16:47:49.831: WARN/System.err(4055): at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
05-03 16:47:49.831: WARN/System.err(4055): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
05-03 16:47:49.831: WARN/System.err(4055): at ksoap2app.main.Ksoap2App.getResults(Ksoap2App.java:44)
05-03 16:47:49.831: WARN/System.err(4055): at ksoap2app.main.Ksoap2App.onCreate(Ksoap2App.java:23)
05-03 16:47:49.831: WARN/System.err(4055): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-03 16:47:49.841: WARN/System.err(4055): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2466)
05-03 16:47:49.841: WARN/System.err(4055): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
05-03 16:47:49.841: WARN/System.err(4055): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
05-03 16:47:49.841: WARN/System.err(4055): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
05-03 16:47:49.841: WARN/System.err(4055): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 16:47:49.841: WARN/System.err(4055): at android.os.Looper.loop(Looper.java:123)
05-03 16:47:49.841: WARN/System.err(4055): at android.app.ActivityThread.main(ActivityThread.java:4370)
05-03 16:47:49.841: WARN/System.err(4055): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 16:47:49.841: WARN/System.err(4055): at java.lang.reflect.Method.invoke(Method.java:521)
05-03 16:47:49.851: WARN/System.err(4055): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 16:47:49.851: WARN/System.err(4055): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 16:47:49.851: WARN/System.err(4055): at dalvik.system.NativeStart.main(Native Method)
我的代码中有什么问题?
答案 0 :(得分:5)
我改变了那样的变量:
private static final String SOAP_ACTION = "http://tempuri.org/GetAuthenticateUser";
private static final String METHOD_NAME = "GetAuthenticateUser";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://stage.mysite.com/FinancialSnapshotServic/Service.asmx";
它解决了问题
答案 1 :(得分:0)
此外,如果您正在使用本地主机,请使用10.0.2.2
How to connect to my http://localhost web server from Android Emulator in Eclipse
http://developer.android.com/tools/devices/emulator.html#networkaddresses
答案 2 :(得分:0)
我想补充dev_android回答。我收到了关于SOAPAction错误的错误,我的错误是SOAP_ACTION网址与NAMESPACE网址不同。它们应该是相同。
$NameSpaceUrl = "http://tempuri.org/";
private static final String SOAP_ACTION = $NameSpaceUrl . "GetAuthenticateUser";
private static final String METHOD_NAME = "GetAuthenticateUser";
private static final String NAMESPACE = $NameSpaceUrl;
private static final String URL = "http://stage.mysite.com/FinancialSnapshotServic/Service.asmx";