我在android中调用soap Web服务,但响应仅来自anyType {}。但响应数据尚未到来。它只是给出了如此多的响应如何获得响应数据。
private static String SOAP_ACTION = "http://tempuri.org/IService1/FindEmployee";
private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "FindEmployee";
private static String URL = "http://192.168.1.9/Employee/Service1.svc?wsdl";
private TextView tv;
StringBuilder sb;
private XmlSerializer writer;
private TextView lblResult1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lblResult1 = (TextView) findViewById(R.id.textView1);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addAttribute("Empid", "R001");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
lblResult1.setText(resultsRequestSOAP.toString());
} catch (Exception e)
{
System.out.println("Error"+e);
}
}
答案 0 :(得分:0)
SoapObject request = new SoapObject(NAMESPACE, methodName);
request.addProperty("Empid", "R001");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
androidHttpTransport
.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
envelope.dotNet = true;
androidHttpTransport.debug = true;
androidHttpTransport.call(newSoapAction, envelope);
InputStream in = new ByteArrayInputStream(androidHttpTransport.responseDump.getBytes());
System.out.println("WS >> Response: "+androidHttpTransport.responseDump); // you will get response overhere
答案 1 :(得分:0)
只需撰写此lblResult1.setText(resultsRequestSOAP.getProperty(0).toString());
而不是lblResult1.setText(resultsRequestSOAP.toString());
它可以帮到你。
如果它不起作用,则意味着您的Web服务不会返回任何响应,即您的Web服务无法从数据库获取数据。
如果您需要更多帮助,请写信给我。