标签:解决 mamicode test detail new too head catch target
参考资料:
利用wsdl2java工具生成webservice的客户端代码
一、wsimport生成
cmd命令示例:
wsimport -encoding utf-8 -s D:\Temp\TempCode -p com.wcf.proxy http://192.168.80.194:9191/UTPWService/metadata
上述命令报错及解决方法:
1、[ERROR] 属性 "Any" 已定义。请使用 <jaxb:property> 解决此冲突。
解决方法:
1)创建xsd.xjb文件(创建txt文档,将下面内容复制进去,再更改文件名称问xsd.xjb)
<?xml version="1.0" encoding="UTF-8"?> <bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" version="2.0"> <globalBindings> <xjc:simple /> </globalBindings> <bindings scd="~xsd:complexType"> <class name="ComplexTypeType"/> </bindings> <bindings scd="~xsd:simpleType"> <class name="SimpleTypeType"/> </bindings> <bindings scd="~xsd:group"> <class name="GroupType"/> </bindings> <bindings scd="~xsd:attributeGroup"> <class name="AttributeGroupType"/> </bindings> <bindings scd="~xsd:element"> <class name="ElementType"/> </bindings> <bindings scd="~xsd:attribute"> <class name="attributeType"/> </bindings> </bindings>
命令中增加参数:-b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb
下面以xsd.xjb放在目录“D:Temp”为例:
wsimport -encoding utf-8 -s D:\Temp\TempCode -p com.wcf.proxy -b http://www.w3.org/2001/XMLSchema.xsd -b D:\Temp\xsd.xjb http://192.168.80.194:9191/UTPWService/metadata
2、[WARNING] 服务 "UTPWService" 不包含任何可用端口。请尝试运行带 -extension 开关的 wsimport。
上述提示表示需增加参数: -extension,否则生成的代码可能没有Service文件。
生成代码的完整命令:
wsimport -extension -encoding utf-8 -s D:\Temp\TempCode -p com.wcf.proxy -b http://www.w3.org/2001/XMLSchema.xsd -b D:\Temp\xsd.xjb http://192.168.80.194:9191/UTPWService/metadata
3、生成代码测试:
public class testclient { public static void main(String[] args) { try { ServiceutpwService = new Service(); String input = "inputStr"; IFooService service = utpwService.getWSHttpBindingIFooService(new javax.xml.ws.soap.AddressingFeature()); String result = service.doFunc("", input); System.out.println(result); } catch(Exception e) { System.out.println(e.getMessage()); } } }
注意:下面代码会报错:MustUnderstand headers:[{http://www.w3.org/2005/08/addressing}Action] are not understood
IFooService service = new FooService().getWSHttpBindingIFooService();
正确写法为:
IFooService service = new FooService().getWSHttpBindingIFooService(new javax.xml.ws.soap.AddressingFeature());
参考资料:WCF Web Service, Java Web Client, MustUnderstand headers not understood?
标签:解决 mamicode test detail new too head catch target
原文地址:https://www.cnblogs.com/cheng2015/p/12971436.html