CXF webservice 动态地址客户端

一、用到的jar包 ,这里的jar包有些是依赖jar包,缺少会报错 。

jar包下载地址:https://download.csdn.net/download/qq_35131811/10274416

    cxf-bundle-2.7.16.jar

    geronimo-jaxb_2.1_spec-1.0.jar

    neethi-3.0.3.jar

    stax2-api-3.1.4.jar

    woodstox-core-5.0.3.jar

    wsdl4j-1.6.3.jar

    xmlschema-core-2.2.3.jar

二、主要代码

package cn.demo.impl;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Service;

import cn.demo.WebServiceDynamicClientService;

public class WebServiceDynamicClientServiceImpl implements
		WebServiceDynamicClientService {

	@Override
	public Object[] dynamicClient(String url, String methodName,Object[] args) {
		try {
			JaxWsDynamicClientFactory jdcf = JaxWsDynamicClientFactory.newInstance();
			Client client = jdcf.createClient(url);
			Object[] invoke = client.invoke(methodName,args);
			return invoke;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}

三、测试代码

package cn.webservice.action;

import cn.webservice.service.impl.WebServiceDynamicClientServiceImpl;

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			WebServiceDynamicClientServiceImpl serice = new WebServiceDynamicClientServiceImpl();
			args = new String[]{"2017-03-05","1","0301,0302"};
			Object[] invoke = serice.dynamicClient("http://localhost:8080/his-portal/webService/demo?wsdl", "demoData", args);
			for (Object object : invoke) {
				
				System.out.println(object.toString());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}

猜你喜欢

转载自blog.csdn.net/qq_35131811/article/details/79475772