我在尝试将SAP中的Web服务与Android连接时遇到问题。我知道这个线程已经有很多问题,但是我尝试了很多解决方案而且没有任何效果。我在androidHttpTransport.call中有这个例外:
org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <html>@1:7 in java.io.InputStreamReade
这是代码:
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private String METHOD_NAME = "ZWS_NOMBRE_SOC";
// our webservice method name
private String NAMESPACE = "urn:sap-com:document:sap:rfc:function";
// Here package name in webservice with reverse order.
private String SOAP_ACTION = NAMESPACE + METHOD_NAME;
// NAMESPACE + method name
private static final String URL = "http://10.0.1.20:8000/sap/bc/srt/rfc/sap/zws_nombre_soci/100/zws_nombre_soci/zws_nombre_soci"; //"http://10.0.1.20:8000/sap/bc/srt/wsdl/srvc_E41F136236A01ED1A2AC083464D902B8/wsdl11/allinone/standard/document?sap-client=100";
private HttpTransportSE androidHttpTransport;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
TextView lb = (TextView) findViewById(R.id.lb1);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("IV_BUKRS", "0001");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = envelope.getResponse();
;
lb.setText(result.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}