使用Glassfish的wsimport从Mago4 ERP的WSDL生成Java构件遇关键方法未生成
解决Mago4 ERP Web服务WSDL在Java wsimport中的兼容性问题
问题背景
我多年来一直通过Java程序调用Microarea旗下意大利ERP系统Mago4暴露的Web服务,近期扩展使用时遇到WSDL兼容性问题,wsimport工具无法生成部分关键方法的代码。
执行的wsimport命令
wsimport http://localhost:10000/Framework.TbGes.TbGes?wsdl -XdisableAuthenticator -generateJWS -XadditionalHeaders -keep -Xnocompile -extension -d generated
报错信息
返回的警告/错误主要分为两类,部分内容如下:
[WARNING] Ignoring operation "RunBatchInUnattendedMode": more than one part bound to body line 1 of http://virtual-1:10000/Framework.TbGes.TbGes?wsdl [WARNING] Ignoring operation "RunReportInUnattendedMode": more than one part bound to body line 1 of http://virtual-1:10000/Framework.TbGes.TbGes?wsdl [WARNING] Non unique body parts! In a port, as per BP 1.1 R2710 operations must have unique operation signature on the wire for successful dispatch. In port TbGesSoap, Operations "GetApplicationDate" and "ClearCache" have the same request body block . Method dispatching may fail, runtime will try to dispatch using SOAPAction line 1 of http://virtual-1:10000/Framework.TbGes.TbGes?wsdl [WARNING] Non unique body parts! In a port, as per BP 1.1 R2710 operations must have unique operation signature on the wire for successful dispatch. In port TbGesSoap, Operations "GetApplicationYear" and "ClearCache" have the same request body block . Method dispatching may fail, runtime will try to dispatch using SOAPAction line 1 of http://virtual-1:10000/Framework.TbGes.TbGes?wsdl [WARNING] Ignoring operation "RunReport": more than one part bound to body line 1 of http://virtual-1:10000/Framework.TbGes.TbGes?wsdl
上述警告中提及的方法未被生成,但这些是必须调用的接口。
相关WSDL片段(以RunReport为例)
导入声明
<xsd:import schemaLocation="http://virtual-1:10000/Framework.TbGes.TbGes?xsd=xsd53" namespace="urn:Microarea.Web.Services.RunReport"/>
消息定义
<wsdl:message name="RunReportIn"> <wsdl:part xmlns:q170="urn:Microarea.Web.Services.RunReport" name="reportNamespace" element="q170:reportNamespace"/> <wsdl:part xmlns:q171="urn:Microarea.Web.Services.RunReport" name="arguments" element="q171:arguments"/> </wsdl:message> <wsdl:message name="RunReportIn_Headers"> <wsdl:part name="HeaderInfo" element="tns:HeaderInfo"/> </wsdl:message> <wsdl:message name="RunReportOut"> <wsdl:part xmlns:q172="urn:Microarea.Web.Services.RunReport" name="return" element="q172:return"/> </wsdl:message>
操作定义
<wsdl:operation name="RunReport"> <soap:operation soapAction="#RunReport" style="document"/> <wsdl:input name="RunReportIn"> <soap:header message="tns:RunReportIn_Headers" part="HeaderInfo" use="literal"/> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="RunReportOut"> <soap:header message="tns:RunReportOut_Headers" part="HeaderInfo" use="literal"/> <soap:body use="literal"/> </wsdl:output> <wsdl:fault name="TBSoapFaultFault"> <soap:fault name="TBSoapFaultFault" use="literal"/> </wsdl:fault> </wsdl:operation>
(注:WSDL中存在重复的RunReport操作定义)
已尝试的方法
添加-XdisableAuthenticator、-XadditionalHeaders等参数,问题未解决;Microarea技术支持以“C#中无此问题”为由拒绝处理。
可行解决方案
方案1:手动修改WSDL文件
- 下载完整的WSDL及关联XSD文件到本地
- 针对“more than one part bound to body”错误:
- 对于包含多个body part的消息(如
RunReportIn),将多个part包装到一个根元素中,修改消息定义为单个part引用这个根元素,同时更新对应的XSD结构 - 移除WSDL中重复的操作定义(如重复的
RunReport操作)
- 对于包含多个body part的消息(如
- 针对“Non unique body parts”错误:
- 为具有相同请求体的操作添加唯一的
soapAction值(确保每个操作的soapAction不重复) - 或修改请求体结构,为每个操作定义唯一的根元素
- 为具有相同请求体的操作添加唯一的
- 使用修改后的本地WSDL文件执行
wsimport
方案2:使用Apache CXF工具替代wsimport
Apache CXF的wsdl2java工具对非标准WSDL的兼容性更强:
- 安装Apache CXF并配置环境变量
- 执行命令:
wsdl2java -d generated -keep -noCompile http://localhost:10000/Framework.TbGes.TbGes?wsdl - 如果仍有警告,可添加
-extension参数启用扩展支持,或通过CXF的绑定文件(binding.xml)自定义处理逻辑,例如指定操作的dispatch策略
方案3:手动编写SOAP客户端代码
如果上述工具无法生成代码,可直接基于SOAP协议手动实现客户端:
- 分析WSDL中的消息结构和SOAP请求格式
- 使用Java的
HttpURLConnection或Apache HttpClient发送SOAP请求 - 手动序列化请求参数为XML,反序列化响应XML为Java对象(可使用JAXB或DOM/SAX解析)
内容的提问来源于stack exchange,提问作者Fabio 2022
相关产品推荐
相关产品推荐

