最近开发一个金蝶EAS webservice 接口。在生成客户端的时候遇到了一点小麻烦,记录一下解决过程,以备参考。

服务端开发完成后,要开发客户端,首先想到了axis这个古老的项目。下载了axis2 1.7.9 的二进制包、解压。

打开一个cmd窗口,输入命令 bin\wsdl2java.bat -uri http://xxx:6888/ormrpc/services/WSSyncApiFacade?wsdl ,直接报错:

log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: Error parsing WSDL
        at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:177)
        at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:50)
        at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: org.apache.axis2.AxisFault: Part 'fault' of fault message '{http://xxxx:6888/ormrpc/services/WSSyncApiFacade}WSInvokeException' must be defined with 'element=QName' and not 'type=QName'
        at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.addQNameReference(WSDL11ToAxisServiceBuilder.java:1375)
        at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateBinding(WSDL11ToAxisServiceBuilder.java:901)
        at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateEndpoint(WSDL11ToAxisServiceBuilder.java:547)
        at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateEndpoints(WSDL11ToAxisServiceBuilder.java:499)
        at org.apache.axis2.description.WSDL11ToAxisServiceBuilder.populateService(WSDL11ToAxisServiceBuilder.java:370)
        at org.apache.axis2.description.WSDL11ToAllAxisServicesBuilder.populateAllServices(WSDL11ToAllAxisServicesBuilder.java:107)
        at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.<init>(CodeGenerationEngine.java:171)
        ... 2 more



猜测是axis版本的问题,经过一番查询,发现了下面一段描述 ,这是解决问题的关键

According to the specification, fault and header message parts must be
defined as document/literal, even if the body is defined as RPC style.
Axis 1.x did not follow the specification in this case. If the body
was defined as RPC style, it also used RPC for the fault and header
definitions.

Axis 1.x 没有遵循规范:fault and header message parts must be defined as document/literal,

金蝶eas8.5 的webservice使用的是axis1.4构建。

知道了问题的原因,解决起来就简单了,直接切换到axis1.4 生成。

懒得写脚本了,直接使用maven下载axis的包,在idea下运行。

maven引入相关包

<dependency>
			<groupId>org.apache.axis</groupId>
			<artifactId>axis</artifactId>
			<version>1.4</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis</groupId>
			<artifactId>axis-jaxrpc</artifactId>
			<version>1.4</version>
		</dependency>
		<dependency>
			<groupId>org.apache.axis</groupId>
			<artifactId>axis-saaj</artifactId>
			<version>1.4</version>
		</dependency>
		<dependency>
			<groupId>wsdl4j</groupId>
			<artifactId>wsdl4j</artifactId>
			<version>1.4</version>
		</dependency>

reimport maven配置文件后,在External Libraries 下找到axis的jar,双击打开包中的WSDL2Java类

右键运行该类,弹出运行参数对话框:

使用axis 1.4 生成金蝶EAS webservice客户端_axis

 

查询参数说明 ,在Program arguments 中填写参数:

-o .\generated\ -u http://xxxx:6888/ormrpc/services/WSSyncApiFacade?wsdl  -pcom.abc.eas.syncapi

基中,-o后面是生成类的输出路径,-u后面是wsdl的url -p是生成的包名

然后Use classpath of module 直接选择当前的模块。

点击运行按钮,生成客户端。

 

 

 

参考文档 :

https://stackoverflow.com/questions/65832248/apache-axis-cannot-find-wsdl2java-class

https://jira.atlassian.com/browse/JRASERVER-12152