【发布时间】:2015-04-29 04:03:29
【问题描述】:
我正在使用下面的代码来调用基于肥皂的网络服务。调用时,我需要从客户端检查调用是否成功。无需等待网络服务的响应。
是否有任何响应代码或以任何方式,客户端会知道调用成功并且传递的有效负载是正确的。
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();
问候, 斯大林
【问题讨论】:
-
如果你使用SOAP库并自己获取WSDL文档会容易得多
-
我的代码本质上应该是通用的,而不是绑定到任何特定的 wsdl。我应该能够调用任何肥皂服务。它只需要 webservice url 和 payload 作为输入。
-
是的,我明白你想要做什么。 HttpURLConnection 确实是一个不错的选择,但是肥皂服务的工作方式是您需要提及 SOAP_ACTION、SOAP_METHOD、SOAP_NAMESPACE。 SOAP_URL,所以它是最好和最容易选择的,你现在有 SOAP 库
-
我希望,你建议我使用 javax.xml.soap.SOAPConnection.call(SOAPMessage request, Object to) throws SOAPException ??
标签: java web-services http soap