在Eclipse中使用Axis2插件自动生成WSDL文件

来源:互联网 时间:1970-01-01

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视图下,项目结构如下:

[java] view plaincopy
  1. package com.sean;  
  2.   
  3. public interface Math {  
  4.     public int add(int a, int b);  
  5. }  

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),文件内容如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   
  3.     xmlns:ns1="http://org.apache.axis2/xsd"   
  4.     xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"   
  5.     xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"   
  6.     xmlns:xsd="http://sean.com"   
  7.     xmlns:xs="http://www.w3.org/2001/XMLSchema"   
  8.     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"   
  9.     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"   
  10.     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"   
  11.     targetNamespace="http://sean.com">  
  12.     <wsdl:types>  
  13.         <xs:schema attributeFormDefault="qualified"   
  14.             elementFormDefault="qualified"   
  15.             targetNamespace="http://sean.com">  
  16.             <xs:element name="add">  
  17.                 <xs:complexType>  
  18.                     <xs:sequence>  
  19.                         <xs:element minOccurs="0" name="args0" type="xs:int"/>  
  20.                         <xs:element minOccurs="0" name="args1" type="xs:int"/>  
  21.                     </xs:sequence>  
  22.                 </xs:complexType>  
  23.             </xs:element>  
  24.             <xs:element name="addResponse">  
  25.                 <xs:complexType>  
  26.                     <xs:sequence>  
  27.                         <xs:element minOccurs="0" name="return" type="xs:int"/>  
  28.                     </xs:sequence>  
  29.                 </xs:complexType>  
  30.             </xs:element>  
  31.         </xs:schema>  
  32.     </wsdl:types>  
  33.     <wsdl:message name="addRequest">  
  34.         <wsdl:part name="parameters" element="xsd:add"/>  
  35.     </wsdl:message>  
  36.     <wsdl:message name="addResponse">  
  37.         <wsdl:part name="parameters" element="xsd:addResponse"/>  
  38.     </wsdl:message>  
  39.     <wsdl:portType name="MathPortType">  
  40.         <wsdl:operation name="add">  
  41.             <wsdl:input message="xsd:addRequest" wsaw:Action="urn:add"/>  
  42.             <wsdl:output message="xsd:addResponse" wsaw:Action="urn:addResponse"/>  
  43.         </wsdl:operation>  
  44.     </wsdl:portType>  
  45.     <wsdl:binding name="MathSoap11Binding" type="xsd:MathPortType">  
  46.         <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>  
  47.         <wsdl:operation name="add">  
  48.             <soap:operation soapAction="urn:add" style="document"/>  
  49.             <wsdl:input>  
  50.                 <soap:body use="literal"/>  
  51.             </wsdl:input>  
  52.             <wsdl:output>  
  53.                 <soap:body use="literal"/>  
  54.             </wsdl:output>  
  55.         </wsdl:operation>  
  56.     </wsdl:binding>  
  57.     <wsdl:binding name="MathSoap12Binding" type="xsd:MathPortType">  
  58.         <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>  
  59.         <wsdl:operation name="add">  
  60.             <soap12:operation soapAction="urn:add" style="document"/>  
  61.             <wsdl:input>  
  62.                 <soap12:body use="literal"/>  
  63.             </wsdl:input>  
  64.             <wsdl:output>  
  65.                 <soap12:body use="literal"/>  
  66.             </wsdl:output>  
  67.         </wsdl:operation>  
  68.     </wsdl:binding>  
  69.     <wsdl:binding name="MathHttpBinding" type="xsd:MathPortType">  
  70.         <http:binding verb="POST"/>  
  71.         <wsdl:operation name="add">  
  72.             <http:operation location="add"/>  
  73.             <wsdl:input>  
  74.                 <mime:content type="application/xml" part="parameters"/>  
  75.             </wsdl:input>  
  76.             <wsdl:output>  
  77.                 <mime:content type="application/xml" part="parameters"/>  
  78.             </wsdl:output>  
  79.         </wsdl:operation>  
  80.     </wsdl:binding>  
  81.     <wsdl:service name="Math">  
  82.         <wsdl:port name="MathHttpSoap11Endpoint" binding="xsd:MathSoap11Binding">  
  83.             <soap:address location="http://localhost:8080/axis2/services/Math"/>  
  84.         </wsdl:port>  
  85.         <wsdl:port name="MathHttpSoap12Endpoint" binding="xsd:MathSoap12Binding">  
  86.             <soap12:address location="http://localhost:8080/axis2/services/Math"/>  
  87.         </wsdl:port>  
  88.         <wsdl:port name="MathHttpEndpoint" binding="xsd:MathHttpBinding">  
  89.             <http:address location="http://localhost:8080/axis2/services/Math"/>  
  90.         </wsdl:port>  
  91.     </wsdl:service>  
  92. </wsdl:definitions>  


相关阅读:
Top