用Eclipse 和 axis1.4 结合来自动生成JAVA代码非常方便。
1. 下载 axis1.4 相关包,解压后取得其中lib 下的所有JAR包,并导入ECLIPSE工程中。
2. 取得服务端提供的 wsdl 描述文件。
3. 在工程中运行 axis 包中的 wsdl2java :
org.apache.axis.wsdl.WSDL2Java
并设置参数
-u F:/MemberManagerFacade.wsdl(可以直接用URL,或者工程内部的相对路径 -u src/wsdl/MemberManagerFacade.wsdl)
-o src/main/java 指定输出的java类目录
-w 生成数组,默认为false
-S true 需要指定一个参数,若为true则会生成客户端骨架代码,若false则用实现的方式生成客户端代码。
4. 运行后自动生成 JAVA代码。
生成的JAVA代码中,除了BEAN外,会有2个接口,3个类
其中 Locator 类中继承了 org.apache.axis.client.Service
创建一个Locator 类就可以获取到调用接口,比如我的代码是这样的:
MemberManageFacadeLocator svc = new MemberManageFacadeLocator();
MemberManageFacadePortType stub = svc.getMemberManageFacadeHttpPort();
//调用
String locationId = stub.queryXXXXNo("xxx", "xxxxx");
// 使用帮组
Usage: java org.apache.axis.wsdl.WSDL2Java [options] WSDL-URI
Options:
-h, --help
print this message and exit
-v, --verbose
print informational messages
-n, --noImports
only generate code for the immediate WSDL document
-O, --timeout <argument>
timeout in seconds (default is 45, specify -1 to disable)
-D, --Debug
print debug information
-W, --noWrapped
turn off support for "wrapped" document/literal
-q, --quiet
do not print any informational or debug messages (except errors)
-s, --server-side
emit server-side bindings for web service
-S, --skeletonDeploy <argument>
deploy skeleton (true) or implementation (false) in deploy.wsdd. Default is false. Assumes --server-side.
-N, --NStoPkg <argument>=<value>
mapping of namespace to package
-f, --fileNStoPkg <argument>
file of NStoPkg mappings (default NStoPkg.properties)
-p, --package <argument>
override all namespace to package mappings, use this packagename instead
-o, --output <argument>
output directory for emitted files
-d, --deployScope <argument>
add scope to deploy.wsdd: "Application", "Request", "Session"
-t, --testCase
emit junit testcase class for web service
-a, --all
generate code for all elements, even unreferenced ones
-T, --typeMappingVersion <argument>
indicate 1.1 or 1.2. The default is 1.1 (SOAP 1.1 JAX-RPC compliant. 1.2 indicates SOAP 1.1 encoded.)
-F, --factory <argument>
name of a custom class that implements GeneratorFactory interface (for extending Java generation functions)
-H, --helperGen
emits separate Helper classes for meta data
-B, --buildFile
emit Ant Buildfile for web service
-U, --user <argument>
username to access the WSDL-URI
-P, --password <argument>
password to access the WSDL-URI
-X, --classpath
additional classpath elements
-i, --nsInclude <argument>
include namespace in generated code
-x, --nsExclude <argument>
exclude namespace from generated code
-c, --implementationClassName <argument>
custom name of web service implementation
-u, --allowInvalidURL
emit file even if WSDL endpoint URL is not a valid URL
-w, --wrapArrays
Prefers building beans to straight arrays for wrapped XML array types (defaults to off).
org.apache.axis.wsdl.Java2WSDL
maven2 自动生成