配置和学习1是一样的
这里就简单使用一下已经存在的webservice 使用起来很简单
先找到一个提供各种webservice的网站:
http://www.webxml.com.cn/zh_cn/index.aspx
使用一个服务:
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx
对应的wsdl就是
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
用生成工具来生成:
wsdl2java -encoding gbk -p org.cc.ws.use -d H:\webservice http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
将生成的java源代码拷入工程
package org.cc.ws.use; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class Start { /** * @param args */ public static void main(String[] args) { JaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean(); factoryBean.setAddress("http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"); factoryBean.setServiceClass(MobileCodeWSSoap.class); MobileCodeWSSoap mcs= (MobileCodeWSSoap)factoryBean.create(); System.out.println(mcs.getMobileCodeInfo("18868800000", null)); } }
显示:
2013-5-9 23:29:28 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass 信息: Creating Service {http://WebXml.com.cn/}MobileCodeWSSoapService from class org.cc.ws.use.MobileCodeWSSoap 18868800000:浙江 杭州 浙江移动全球通卡
一次简单调用就完成了
用的是SOAP的方式 其实还可以看到还提供了HttpGet和HttpPost的方式 这里就不多说了呢.