</pre><pre name="code" class="java">public void testWeb() {
String requestSoapData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" "
+ "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "<soapenv:Body>"
+ "<ns1:getPrescsOfPatient soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:ns1=\"http://service.webService.com\">"
+ "<cardNumber>A12345678</cardNumber>"
+ "<prescStatus>0</prescStatus>"
+ "</ns1:getPrescsOfPatient>"
+ "</soapenv:Body>" + "</soapenv:Envelope>";
String response = uniform(
"http://192.168.23.166:8080/drug/com/webService/service/prescService?wsdl",
requestSoapData, "UTF-8");
System.out.println(response);
}
HTTPclient通过soap协议访问cxf写的webservice服务端的方法。
public String uniform(String url, String requestData, String charset) {
HttpPost httppost = new HttpPost(url);
StringEntity reqEntity = new StringEntity(requestData, charset);
httppost.setEntity(reqEntity);
HttpClient client = HttpClients.createDefault();
try {
CloseableHttpResponse response = (CloseableHttpResponse) client
.execute(httppost);
InputStream is = response.getEntity().getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = is.read()) != -1) {
baos.write(i);
}
return baos.toString(charset);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}