当前位置 : 主页 > 网页制作 > Nodejs >

CXF进行WebService客户端调用的两种方式

来源:互联网 收集:自由互联 发布时间:2021-06-24
1、JaxWsDynamicClientFactory: JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance(); Client client = clientFactory.createClient("http://IP:端口/iemr/webservice/IEMRWebService?wsdl"); // 下面一段处理 We

1、JaxWsDynamicClientFactory:

JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();  
Client client = clientFactory.createClient("http://IP:端口/iemr/webservice/IEMRWebService?wsdl");  
// 下面一段处理 WebService接口和实现类namespace不同的情况  
// CXF动态客户端在处理此问题时,会报No operation was found with the name的异常  
String wsOperation="getMrPdfList";//ws调用方法
Endpoint endpoint = client.getEndpoint();  
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), wsOperation);  
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();  
if (bindingInfo.getOperation(opName) == null) {  
 for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {  
	 if (wsOperation.equals(operationInfo.getName().getLocalPart())) {  
		 opName = operationInfo.getName();  
		 break;  
	 }  
 }  
} 
Object[] result = client.invoke(opName, enPk, true, false);  
String xmlReturn=(String)result[0]; 

 

2、JaxWsProxyFactoryBean:

private UnDocPdfWebService createUnDocPdfWs(){
	JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    //带有@WebService注解的接口类
	factory.setServiceClass(UnDocPdfWebService.class);
    //不带?wsdl的WS调用地址
	factory.setAddress(unDocPdfWsUrl);
	UnDocPdfWebService service = (UnDocPdfWebService)factory.create();
	return service;
}
网友评论