WebService接口调用

最近项目中有朋友咨询我webService接口的调用,在这里总结并分享一下,我对webService方法的调用。


一、webService接口调用工具类

public class WebService {
	private WebService() {
		throw new IllegalAccessError("CallWebServiceInterface class");
	}

	public static <E> E getWebServiceClient(String url, Class<E> clazz, int connectionTimeout, int receiveTimeout) {
		JaxWsProxyFactoryBean proxy = new JaxWsProxyFactoryBean();
		proxy.setServiceClass(clazz);
		proxy.setAddress(url);
		@SuppressWarnings("unchecked")
		E client = (E) proxy.create();
		// 配置超时时间
		Client clientProxy = ClientProxy.getClient(client);
		HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
		HTTPClientPolicy policy = new HTTPClientPolicy();
		policy.setConnectionTimeout(connectionTimeout); // 连接超时时间
		policy.setReceiveTimeout(receiveTimeout);// 请求超时时间
		conduit.setClient(policy);
		return client;
	}

	public static <E> E getWebServiceClient(String url, Class<E> clazz) {
		return getWebServiceClient(url, clazz, 5000, 5000);
	}
}


二、webService服务接口

@WebService(targetNamespace = "http://biz.cos.interfaces.ccs.sf.com/")
public interface webServiceTest{
	

	@WebMethod
	List<String> queryAddressByPhone(String args);

}

注意:
1、webService注解上的targetNamespace是接口提供方的分包地址,获取方式可以直接访问webService接口地址返回的XML文件中获取;
2、接口中的方法名必须带webMethod注解,并且接口方法必须与提供方的接口一模一样;


三、WebService接口的调用

参数详解:
1、url为接口供应商提供的webService接口地址
2、args为webService方法需求的参数

public List<String> queryAddressByPhone(String url , String args) {
	webServiceTest client = WebService.getWebServiceClient(url, webServiceTest.class);
	List<String> Result = client.queryAddressByPhone(args);
	return Result;
}











  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值