我使用以下代码来调用基于soap的webservice。在调用时我需要从客户端检查调用是否成功。无需等待网络服务的响应。
是否有任何响应代码或以任何方式,客户端将知道调用成功并且传递的有效负载是正确的。
url = new URL(webserviceURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
String xmlInput =
" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soapenv:Body>\n" + bodyContent + " </soapenv:Body>\n" + "</soapenv:Envelope>";
byte[] buffer = new byte[xmlInput.length()];
buffer = xmlInput.getBytes();
bout.write(buffer);
byte[] b = bout.toByteArray();
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
此致 斯大林
答案 0 :(得分:0)
SoapObject send = new SoapObject("Your NAMESPACE"," Your METHODS");
//现在添加您需要将其发送到您的Web服务方法所需的参数,如果没有,则添加无
send.addProperty("intId", 0);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(send);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE("Your SOAP_ADDRESS");
androidHttpTransport.call("Your SOAP_ACTION", envelope);
SoapObject result = (SoapObject) envelope.getResponse();
String s = result.toString();
确保将ksop2库添加到项目中以使用它,
您可以从提供给您的WSDL文档中收集有关 SOAP_ADDRESS , NAMESPACE , METHODS 和 SOAP_ADDRESS 的信息在浏览器中运行它