Fork me on GitHub

使用wsimport命令构建WebService

Java与WCF交互,之前我一直是soap的xml参数或者http协议,JDK1.6.X 后可以使用JAX-WS生成客户端代码
wsimport则生成Java的客户端
wsimport -keep -p com.webservice.client
http://172.23.100.25/HomeInns.CRS.SettingCenter.WcfHostSvr/PaymentRuleService/?wsdl
wsimport -s generate http://172.23.100.25/HomeInns.CRS.SettingCenter.WcfHostSvr/PaymentRuleService/?wsdl

说明几点:

1.生成的代理类为JDK7.x+的构造 取出即可
2.XMLGregorianCalendarImpl时间问题当要传递参数
3.JAXBElement参数问题与,调用ObjectFactory中的公用方法,而不用自己还要new JAXBElement<String>(new QName(
http://test, "username"),String.class,"dfdfs");
直接调用factory.createUserUsername("Irving")返回JAXBElement<String>类型

                ObjectFactory factory = new ObjectFactory();
                OrderQuery query = factory.createOrderQuery();
                GregorianCalendar calendar = (GregorianCalendar) GregorianCalendar.getInstance();
                calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-05-10 09:44:46"));//20130510 09444 3898
                query.setPayCd(factory.createOrderQueryPayCd("21"));
                query.setOrderNo(Integer.parseInt(orderNo));
                query.setOldTransDate(new XMLGregorianCalendarImpl(calendar));
                CancelOrderService canOrderService = new CancelOrderService();
                ICancelOrderService portTypeOrderService = canOrderService.getBasicHttpBindingICancelOrderService();
                Holder<Boolean> canbeOrderResult = new Holder<Boolean>();
                Holder<Boolean> result = new Holder<Boolean>();
                Holder<String> errMsg = new Holder<String>();
                portTypeOrderService.orderCanBeCanceled(query, canbeOrderResult, result, errMsg);
                logger.info(result.value.toString());

 wsimport options.

Option

Description

-d <directory>  

Specify where to place generated output files

-b <path>  

Specify external JAX-WS or JAXB binding files (Each <file> must have its own -b)

-B <jaxbOption>

Pass this option to JAXB schema compiler

-catalog

Specify catalog file to resolve external entity references, it supports TR9401, XCatalog, and OASIS XML Catalog format. Please read the documentation of catalog and see catalog sample.

-extension  

Allow vendor extensions (functionality not specified by the specification). Use of extensions may result in applications that are not portable or may not interoperate with other implementations

-help  

Display help

-httpproxy:<host>:<port>  

Specify an HTTP proxy server (port defaults to 8080)

-keep  

Keep generated files

-p  
Specifying a target package via this command-line option, overrides any wsdl and schema binding customization for package name and the default package name algorithm defined in the specification
-s <directory>  

Specify where to place generated source files

-verbose  

Output messages about what the compiler is doing

-version  

Print version information

-wsdllocation <location> 
@WebServiceClient.wsdlLocation value
-target  
Generate code as per the given JAX-WS specification version. version 2.0 will generate compliant code for JAX-WS 2.0 spec.
-quiet  
Suppress wsimport output

Refer:http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

 

posted @ 2013-05-10 15:57  花儿笑弯了腰  阅读(791)  评论(0编辑  收藏  举报