JDK版本:1.7update65
Eclipse版本:Juno Service Release 2(4.2.2)
首先在Eclipse中安装Axis2的插件:
1,下载Axis2插件,最新版本为1.6.2:http://www.apache.org/dyn/mirrors/mirrors.cgi/axis/axis2/java/core/1.6.2/axis2-eclipse-codegen-plugin-1.6.2.zip
2,将zip压缩包中的org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar放置在%ECLIPSE_HOME%\plugins路径下
3,重启Eclipse
安装完成后就可以使用安装好的插件生成WSDL文件了
1,创建一个普通的Java项目,在该项目下创建一个接口,在Navigator视图下,项目结构如下:
package com.sean;
public interface Math {
public int add(int a, int b);
}
2,选择Eclipse菜单栏中的File -> New -> Other...,在弹出的对话框中选择Axis2 Code Generator,然后选择Next
3,然后选择通过Java源文件生成WSDL
4,Fully Qualified Class name中填写用来生成WSDL的Java类全名称
然后通过Add Folder按钮添加Java类编译后生成的.class文件(Math.class)所在路径
最后点击Test Class Loading...按钮
当测试通过时(按钮右侧显示Class file loaded successfully),才可点击Next按钮
5,WSDL文件属性值,这里使用默认的即可
6,选择将WSDL文件生成在本地文件系统,并且选择好WSDL文件的生成路径及文件名
点击Finish后,将在指定位置生成WSDL文件(Math.wsdl),文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://sean.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
targetNamespace="http://sean.com">
<wsdl:types>
<xs:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="http://sean.com">
<xs:element name="add">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" type="xs:int"/>
<xs:element minOccurs="0" name="args1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="addResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="addRequest">
<wsdl:part name="parameters" element="xsd:add"/>
</wsdl:message>
<wsdl:message name="addResponse">
<wsdl:part name="parameters" element="xsd:addResponse"/>
</wsdl:message>
<wsdl:portType name="MathPortType">
<wsdl:operation name="add">
<wsdl:input message="xsd:addRequest" wsaw:Action="urn:add"/>
<wsdl:output message="xsd:addResponse" wsaw:Action="urn:addResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MathSoap11Binding" type="xsd:MathPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="add">
<soap:operation soapAction="urn:add" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="MathSoap12Binding" type="xsd:MathPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="add">
<soap12:operation soapAction="urn:add" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="MathHttpBinding" type="xsd:MathPortType">
<http:binding verb="POST"/>
<wsdl:operation name="add">
<http:operation location="add"/>
<wsdl:input>
<mime:content type="application/xml" part="parameters"/>
</wsdl:input>
<wsdl:output>
<mime:content type="application/xml" part="parameters"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Math">
<wsdl:port name="MathHttpSoap11Endpoint" binding="xsd:MathSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/Math"/>
</wsdl:port>
<wsdl:port name="MathHttpSoap12Endpoint" binding="xsd:MathSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/Math"/>
</wsdl:port>
<wsdl:port name="MathHttpEndpoint" binding="xsd:MathHttpBinding">
<http:address location="http://localhost:8080/axis2/services/Math"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>