1. 程式人生 > >wsdl介面,用cmd生成客戶端程式碼

wsdl介面,用cmd生成客戶端程式碼

wsimport -s D:\cos\pa -p com.sf.customer.service.core.web.ws.client.cos.paramTypeService -keep http://127.0.0.1:8080/cos_webservice/services/EcosParamTypeService?wsdl
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

public class WebServiceUtil {
	private static final long CONNECT_TIMEOUT = 1000L * 5;
	private static final long RECIVE_TIMEOUT = 1000L * 15;
	
	/**
	 * 代理方式獲得webservice客戶端[CXF](此方法主要作用是設定超時時間)
	 */
	@SuppressWarnings("unchecked")
	public static <T> T getClient(Class<T> classz, String url) {
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setAddress(url);
		factory.setServiceClass(classz);
		T obj = (T) factory.create();
		Client proxy = ClientProxy.getClient(obj);
		HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setConnectionTimeout(CONNECT_TIMEOUT);
		policy.setReceiveTimeout(RECIVE_TIMEOUT);
		conduit.setClient(policy);
		return obj;
	}
	
	
}


EcosQueryClaimServicePortType client = WebServiceUtil.getClient(EcosQueryClaimServicePortType.class,url);
resultStr = client.getClaimDetail(jsonObj.toString());