欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CXF进行WebService客户端调用的两种方式 博客分类: java

程序员文章站 2024-02-16 22:04:46
...

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;
}