我使用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();
}
}
答案 0 :(得分:0)
我解决了从类SoapSerializationEnvelope创建遗产的问题。
我也改变了这个属性。
soapEnvelope.implicitTypes=true;
soapEnvelope.setAddAdornments(false);
像这样:
import org.ksoap2.serialization.SoapSerializationEnvelope;
import java.io.IOException;
import org.xmlpull.v1.XmlSerializer;
public class SoapSerEnv extends SoapSerializationEnvelope {
public SoapSerEnv(int version) {
super(version);
// TODO Auto-generated constructor stub
}
public void write(XmlSerializer writer)
throws IOException
{
writer.setPrefix("i", xsi);
writer.setPrefix("d", xsd);
writer.setPrefix("c", enc);
writer.setPrefix("soapenv", env); // era writer.setPrefix("v", env)
writer.startTag(env, "Envelope");
writer.startTag(env, "Header");
writeHeader(writer);
writer.endTag(env, "Header");
writer.startTag(env, "Body");
writeBody(writer);
writer.endTag(env, "Body");
writer.endTag(env, "Envelope");
}
}