我想通过使用 ksoap2 来使用来自 andriod websevice 程序的肥皂网络服务。为此,我编写了以下代码。当我在 Android 模拟器中运行它时,我的 logcat 中没有得到响应。我的 web 服务返回类型结果是 XML 文件。
public class SoapWebservicesExampleActivity extends Activity {
/** 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=*********";
//i am appending the Username and password as URL Parameters.
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";
// i am getting the method name tns from WSDL file.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); // set up
request.addProperty("Input", "1460");
// request.addProperty("Langu", "d");
//one property in the webservices
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, envelope);
// by using call method we can call the services
SoapObject response = (SoapObject)envelope.getResponse();
String str = response.getProperty(0).toString();
System.out.println("theeeeeeeeeee"+str);
//printing the respose here
}
catch(SocketException ex){
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
但这里的问题是我遇到了这个异常,我正在添加 ksoap2 jar 文件。
05-29 15:37:54.403: WARN/System.err(383): 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@40547218)
05-29 15:37:54.403: WARN/System.err(383): at org.kxml2.io.KXmlParser.exception(KXmlParser.java:273)