生成webservice客户端的一些坑

一、undefinedelement declaration 's:schema'(来自:https://blog.csdn.net/binbinxyz/article/details/8906717)
用<s:any minOccurs="2" maxOccurs="2"/>替代<s:element ref="s:schema"/><s:any />    

二、undefined simple or complex type 'soap-enc:Array'  (来自:http://sky-sz.iteye.com/blog/1480937)
1.在浏览器中打开webservice url,保存wsdl文件,如ContentService.xml 
2.通过cxf命令“wsdl2java –d E:/file –frontend jaxws21 –client C:\ ContentService.xml”生成客户端代码 
3.若报WSDLToJava Error: Thrown by JAXB : undefined simple or complex type 'soap-enc:Array' , 
则需要在生成的文件中找到 
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />, 
在浏览器中打开http://schemas.xmlsoap.org/soap/encoding/, 
保存文件soap-encoding.xsd, 
然后修改成<import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soap-encoding.xsd"/>, 
再运行上面的命令即可。
4.如果需要NTLM认证,则需在代码中加入如下的代码:

Client client = ClientProxy.getClient(port);  
HTTPConduit http = (HTTPConduit) client.getConduit();  
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();   
httpClientPolicy.setConnectionTimeout(36000);  
httpClientPolicy.setAllowChunking(false);  
http.setClient(httpClientPolicy);  
http.getAuthorization().setAuthorizationType("NTLM");   
http.getAuthorization().setUserName("xxxx");  
http.getAuthorization().setPassword("xxxxx"); 

三、具有相同名称 "xxxxx" 的类/接口已在使用。请使用类定制设置来解决此冲突。
wsdl2java命令添加参数 -autoNameResolution 解决

四、属性 "xxxx" 已定义。请使用 &lt;jaxb:property> 解决此冲突 (三、四  均来自:https://www.cnblogs.com/boazy/p/9131438.html)

采用xjb文件方式重命名处理解决(wsdl2java命令添加参数 -b d:/xxx.xjb)

wsdl2java -d D:\boazy\Desktop\ama D:\boazy\Desktop\20180529_145043\1ASIWGUGGUG_PDT_20180529_145042-ama.wsdl -b D:\boazy\Desktop\20180529_145043\zz_xjb.xjb

以 "any" 为例(参考:https://blog.csdn.net/yfisaboy/article/details/38376511)
添加配置文件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>

使用命令  wsimport(或者wsdl2java) -b http://www.w3.org/2001/XMLSchema.xsd -b xsd.xjb SecureConversation.wsdl

五、不允许 'file' 访问或者http请求之类的
(参考:https://blog.csdn.net/SpicyCoder/article/details/78920837    
https://stackoverflow.com/questions/42928279/wsimport-two-declarations-cause-a-collision)
在jdk的安装路径下的jre\lib下(我的路径为/usr/local/jdk1.8.0_151/jre/lib),添加一个属性文件jaxp.properties,并写上如下内容

javax.xml.accessExternalSchema = all
javax.xml.accessExternalDTD=all

wsimport 也可以在命令行上加参数 参见上面的stackoverflow地址

六、乱码
-encoding utf-8

七、发现一个新bug 

URI is not hierarchical  :原来是自己不在bin目录

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值