我是一个非常新的 Android Soap Web 服务我对使用 Ksoap2 在 Android 中使用肥皂 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