SOAP
Java测试代码
java测试结果
SoapUI测试工具测试结果
问题解决
为了Java能够调用WebService的方法,所以。NETP写的WebServiced的每个方法都要声明为Rpc方法,即添加"[SoapRpcMethod…]".
例如:[WebMethod]
[SoapRpcMethod(Use=SoapBindingUse.Literal,Action= http://tempuri.org/HelloWorld", RequestNamespace = “http://tempuri.org/”, ResponseNamespace = “http://tempuri.org/”)]
完整的java代码
String inXml = "<request><requestHead><busCode>1024</busCode><terminalNo>LDKQZZJ001</terminalNo><operNo>LDKQZZJ001</operNo><tradeDate>20200508</tradeDate><tradeTime>141908</tradeTime><mzlx>6</mzlx><transNo>000000</transNo></requestHead><data><requestPage>1</requestPage><pageSize>15</pageSize></data></request>";
// 指出service所在完整的URL
String url = "http://192.168.0.117:10139/his_w.asmx";
// 调用接口的targetNamespace
// targetNamespace 就是你用浏览器打开url 路径加上?wsdl,即http://xxx/WebService.asmx?wsdl
// 中的targetNamespace属性值
String targetNamespace = "http://192.168.0.117:10139/his_w.asmx?WSDL/";
// 所调用接口的方法method
String method = "his_f";
String name="XMLRequset";
public static void test4(String xml,String url,String targetNamespace,String method,String name) throws ServiceException, MalformedURLException, RemoteException{
String service_url =url;
Service ser = new Service();
Call call = (Call) ser.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
QName opAddEntry = new QName(targetNamespace,method);
call.setOperationName(opAddEntry);
call.addParameter(name, XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING); Object[] opAddEntryArgs = new Object[] {xml };
String result = (String) call.invoke(opAddEntryArgs);
try {
call.invoke(targetNamespace, method, opAddEntryArgs);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("result:" + result);
}