我正在使用Ksoap2 api来集成Web服务。不需要用户输入的Web服务正常运行。
但是在输入的情况下,它给出了SoapFault异常。
我在这里分享代码和细节。
我为这个方法提供了一个包络字符串:
文章:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:def="http://DefaultNamespace">
<soapenv:Header/>
<soapenv:Body>
<def:article soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<articleID xsi:type="xsd:double">$ARTICLEID</articleID>
</def:article>
</soapenv:Body>
</soapenv:Envelope>
我的代码:
private String getNewsDetails() {
String URL = "http://heinrich.house.gov/common/site/mobile.cfc?WSDL";
String NAMESPACE = "http://DefaultNamespace/";
String METHOD_NAME = "article";
String SOAP_ACTION = "http://DefaultNamespace/article";
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
request.addProperty("articleID", "590"); //590 or 592 etc... for test-case
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
// envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
try {
androidHttpTransport.call(SOAP_ACTION,envelope);
resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Log.e("Response", "getNewsDetails..." + resultsRequestSOAP);
return resultsRequestSOAP.toString();
} catch (IOException e) {
Log.e("TAG","IOException...."+e);
new AlertDialog.Builder(this).setTitle("Error")
.setMessage(e.getMessage()).setPositiveButton("OK", null)
.show();
} catch (XmlPullParserException e) {
Log.e("TAG","XmlPullParserException...."+e);
new AlertDialog.Builder(this).setTitle("Error")
.setMessage(e.getMessage()).setPositiveButton("OK", null)
.show();
}
return null;
}
以下是回复:
04-20 18:32:24.245: ERROR/AndroidRuntime(940): FATAL EXCEPTION: main
04-20 18:32:24.245: ERROR/AndroidRuntime(940): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.demo.view/com.demo.view.Demo}: java.lang.ClassCastException: org.ksoap2.SoapFault
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.os.Looper.loop(Looper.java:123)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread.main(ActivityThread.java:3647)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at java.lang.reflect.Method.invoke(Method.java:507)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at dalvik.system.NativeStart.main(Native Method)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at com.demo.view.Demo.getNewsDetails(Demo.java:141)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at com.demo.view.Demo.onCreate(Demo.java:36)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
04-20 18:32:24.245: ERROR/AndroidRuntime(940): ... 11 more
答案 0 :(得分:0)
从网址字符串中删除“ ?WSDL
”部分。