public static String callLis(String url, String reqStr,String method) throws Exception {
String resStr = invokeRemoteFuc(url, method, reqStr);
return resStr;
}
public static String invokeRemoteFuc(String url, String method, String reqStr) throws Exception {
JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
Client client = factory.createClient(url);
// 下面一段处理 WebService接口和实现类namespace不同的情况
// CXF动态客户端在处理此问题时,会报No operation was found with the name的异常
Endpoint endpoint = client.getEndpoint();
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), method);
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
if (method.equals(operationInfo.getName().getLocalPart())) {
opName = operationInfo.getName();
break;
}
}
}
Object[] res = client.invoke(opName, reqStr);
return res[0].toString();
}
cxf动态调用webService
于 2018-09-30 13:48:02 首次发布