package com.appu.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;
public class SampleFinalSapActivity extends Activity {
/** Called when the activity is first created. */
private final String NAMESPACE ="urn:sap-com:document:sap:soap:functions:mc-style";//this is my server namespace..
private final String METHOD_NAME ="ZMATERIALS_GROUP_LIST";
private final String SOAP_ACTION = NAMESPACE + "/" + METHOD_NAME;
private final String URL ="http://************:8000/sap/bc/srt/wsdl/srvc_14DAE9C8D79F1EE197AD09B4D05C4345/wsdl11/allinone/ws_policy/document?sap-client=800&sap-user=*****&sap-password=******";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("Language", "d");
//这是wsdl文件中的一个属性
System.out.println("the Request is :::::"+Request);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
System.out.println("TRANSPORT:"+androidHttpTransport);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
androidHttpTransport.debug = true; //this is optional, use it if you don't want to use a packet sniffer to check what the sent message was (httpTransport.requestDump)
//Object result = envelope.getResponse(); //getting response here
//SoapPrimitive result1 = (SoapPrimitive)envelope.bodyIn;
// System.out.println("Result : " + result1.toString());
SoapObject response = (SoapObject)envelope.getResponse();
System.out.println("RESPONSE:"+response);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
When I run this application I got the exception:02-04 09:31:37.213: WARN/System.err(538): 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@4052d188)
我该如何解决?在这里我使用Ksoap2.jar来调用webservices是否有任何替代方法可以使用android调用sap soap webservices? 在此先感谢...
答案 0 :(得分:0)
可能是代码中的一个小错误。我无法理解发现错误。我认为URL中可能存在问题。 也许你可以参考我的答案。 Android Java connect to online database 工作代码发布在那里。