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 @   花儿笑弯了腰  阅读(792)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示