我是非常新的Android Soap Web服务我对使用Ksoap2在Android中使用soap web服务有一些了解,我编写了以下代码:使用ksoap2.jar我从WSDL文件中获取了名称空间和方法名称
package com.soapwebservices.pack;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SampleWSExampleActivity extends Activity {
private static final String TAG = null;
/** Called when the activity is first created. */
final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
final String URL = "http://***************:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE196F1FC6C6518A345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=********&sap-password=*******";
final String METHOD_NAME = "Z_GET_CUST_GEN";
final String SOAP_ACTION = "urn:sap-com:document:sap:soap:functions:mc-style/Z_GET_CUST_GEN";
// private static final String[] sampleACTV = new String[];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
System.out.println("THE SOAP RESPONSE"+resultsRequestSOAP);
//ACTV.setHint("Received :" + resultsRequestSOAP.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
when i run this program i got the following Exception but in some examples i got the success please see once and let me know where i am doing the mistake
08-20 15:21:40.296: WARN/System.err(1668): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions targetNamespace='urn:sap-com:document:sap:soap:functions:mc-style'>@1:686 in java.io.InputStreamReader@4052f658)
How can handle that exc
答案 0 :(得分:0)
你的代码可能没什么问题......
在意识到我没有将客户端指向我的服务后,我解决了我的XMLPullParser异常。它希望能够使用SOAP响应和请求,但是看到了wsdl。弄清楚这很棘手。我不确定你的System.err(1668)是什么,但我建议你这样做。
下载并附加android-ksoap2源代码,这样您就可以进入调用(F5),以便在调试ksoap2包中引发错误的位置时查看。
https://github.com/mosabua/ksoap2-android/downloads
和
Install and run the free SoapUI来测试web服务,并确切地找出正确的Action,方法,URL和命名空间,因为如果你的代码没问题,它们很可能是一个问题。这个介绍视频的前2分钟是我测试服务所需的全部内容。
最后用不同的语言编写一个简单的客户端 - 一旦我为web服务的项目添加了Web引用,我发现在VB.NET express中很容易做到。 (这使我在SoapUI的帮助下使我的WS-I符合wsdl)
祝你好运找到解决方案。