我试图在android中使用ksoap2和web服务,但我想我无法从web服务得到响应。谁知道我为什么会收到这个错误? “org.xmlpull.v1.XmlPullParserException:expected:START_TAG”
我的代码是:
public class ANDROIDsapActivity extends Activity {
/** Called when the activity is first created. */
private static final String NAMESPACE = "urn:sap-com:document:sap:soap:functions:mc-style";
private static final String URL = "http://192.168.2.5:8000/sap/bc/srt/wsdl/bndg_E0DFBFD4F407C3F1A6A000155D02060A/wsdl11/allinone/ws_policy/document?sap-client=500";
private static final String SOAP_ACTION = "zws_get_customer";
private static final String METHOD_NAME = "ZfGetCustomers";
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("IM_NAME","M");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(Request);
soapEnvelope.encodingStyle = SoapSerializationEnvelope.ENC2003;
soapEnvelope.bodyOut = Request;
soapEnvelope.dotNet = true;
soapEnvelope.encodingStyle = SoapSerializationEnvelope.XSD;
// AndroidHttpTransport aht = new AndroidHttpTransport(URL);
HttpTransportSE aht = new HttpTransportSE(URL);
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
headers.add(new HeaderProperty("Authorization", "basic " +
Base64.encode("username:password".getBytes())));
try {
aht.call(SOAP_ACTION, soapEnvelope,headers);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();
tv.setText("Status: " + resultString);
} catch (Exception e) {
// TODO: handle exception
tv.setText(e.toString());
}
}
}
我的完整错误是:
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:sapsoap:functions:mc-style'>
@1:630 in java.io.InputStreamReader@43e50a10
我陷入了这个错误,我不能再继续了。 请帮忙!
编辑:我已经解决了这个问题。请在评论和答案之后阅读我的答案。 我希望在某些事情上我会为某人提供帮助。
答案 0 :(得分:1)
我通过更改Web服务样式解决了我的问题。如果要集成SAP和android,请使用Restful webservice系统而不是SOAP。