我使用 ksoap2 使用 Web 服务应用程序,但显示错误“SoapFault - faultcode: 'Sender' faultstring: 'WEBSERVICE ERROR: Soap Prefix Missing”。
我注意到 ksoap2 在我的标签中添加了单词。收到的示例 xml:
<CUSRID i:type="d:string">teste</CUSRID><CPASSID i:type="d:string">teste</CPASSID><CUPC i:type="d:string">produto</CUPC>
这是原始标签:
<CUSRID>STRING</CUSRID><CPASSID>STRING</CPASSID><CUPC>STRING</CUPC>
这是我的代码android:
private static final String SOAP_ACTION = "http://187.75.181.76:8090/RETORNASTK";
private static final String METHOD_NAME = "RETORNASTK";
private static final String NAMESPACE = "http://187.75.181.76:8090/";
private static final String URL = "http://187.75.181.76:8090/ws/WSAPPSTOCK.apw";
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Bundle extras = data.getExtras();
String result = extras.getString("SCAN_RESULT");
EditText desc = (EditText) findViewById(R.produto.desc);
desc.setText(result);
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("CUSRID","teste");
Request.addProperty("CPASSID","teste");
Request.addProperty("CUPC",result);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(Request);
HttpTransportSE http_transport = new HttpTransportSE(URL);
try {
http_transport.call(SOAP_ACTION,soapEnvelope);
SoapObject obj, obj1, obj2;
obj = (SoapObject) soapEnvelope.getResponse();
obj1 = (SoapObject) obj.getProperty("STRUCTSTK");
for (int i = 0; i < obj1.getPropertyCount(); i++) {
// the method getPropertyCount() and return the number of rows
obj2 = (SoapObject) obj1.getProperty(i);
obj2.getProperty(0).toString();// value of column 1
obj2.getProperty(1).toString();// value of column 2
// like that you will get value from each column
}
} catch (Exception e) {
e.printStackTrace();
}
}