Chinaunix首页 | 论坛 | 博客
  • 博客访问: 900032
  • 博文数量: 322
  • 博客积分: 6688
  • 博客等级: 准将
  • 技术积分: 3626
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-19 11:26
文章分类

全部博文(322)

文章存档

2013年(5)

2012年(66)

2011年(87)

2010年(164)

分类: Java

2011-04-06 15:34:49

WSDL文件如下:UserManagement.wsdl
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <wsdl:definitions xmlns:soap=""
  3.     xmlns:tns="" xmlns:wsdl=""
  4.     xmlns:xsd="" name="UserManagement"
  5.     targetNamespace="">
  6.     <wsdl:types>
  7.         <xsd:schema targetNamespace="">

  8.             <xsd:element name="InsertUserRequest">
  9.                 <xsd:complexType>
  10.                     <xsd:sequence>
  11.                         <xsd:element name="User" type="tns:User" />
  12.                     </xsd:sequence>
  13.                 </xsd:complexType>
  14.             </xsd:element>

  15.             <xsd:element name="InsertUserResponse">
  16.                 <xsd:complexType>
  17.                     <xsd:sequence>
  18.                         <xsd:element name="UserID" type="xsd:string" />
  19.                     </xsd:sequence>
  20.                 </xsd:complexType>
  21.             </xsd:element>

  22.             <xsd:element name="InsertUserFault">
  23.                 <xsd:complexType>
  24.                     <xsd:sequence>
  25.                         <xsd:element name="SoapFaultException" type="xsd:string"></xsd:element>
  26.                     </xsd:sequence>
  27.                 </xsd:complexType>
  28.             </xsd:element>

  29.             <xsd:complexType name="User">
  30.                 <xsd:sequence>
  31.                     <xsd:element name="UserIDString" type="xsd:string"></xsd:element>
  32.                     <xsd:element name="UserNameString" type="xsd:string"></xsd:element>
  33.                     <xsd:element name="******Enum" type="tns:***Enum"></xsd:element>
  34.                     
  35.                     <!-- int===>java.int -->                    
  36.                     <xsd:element name="AgeInt" type="xsd:int"></xsd:element>
  37.                     <!-- integer===>java.BigInteger -->
  38.                     <xsd:element name="AgeInteger" type="xsd:integer"></xsd:element>
  39.                     
  40.                     <!-- time===>java.XMLGregorianCalendar -->
  41.                     <!-- date===>java.XMLGregorianCalendar -->
  42.                     <!-- dateTime===>java.XMLGregorianCalendar -->
  43.                     <xsd:element name="CreateTime" type="xsd:time"></xsd:element>
  44.                     
  45.                     <xsd:element name="IsSleepBoolean" type="xsd:boolean"></xsd:element>
  46.                     
  47.                     <!-- maxOccurs="unbounded"===>java.List<> -->
  48.                     <xsd:element name="HobbyList" type="xsd:string" maxOccurs="unbounded"></xsd:element>
  49.                     
  50.                     <xsd:element name="Goods" type="tns:Good" maxOccurs="unbounded"/>
  51.                     
  52.                     <xsd:choice>
  53.                         <xsd:element name="choice1" type="xsd:string"></xsd:element>
  54.                         <xsd:element name="choice2" type="xsd:int"></xsd:element>
  55.                     </xsd:choice>                    
  56.                 </xsd:sequence>
  57.             </xsd:complexType>
  58.             
  59.             <xsd:complexType name="Good">
  60.                 <xsd:sequence>
  61.                     <xsd:element name="GoodIDInt" type="xsd:int"/>
  62.                     <xsd:element name="GoodTypeString" type="xsd:string"/>
  63.                 </xsd:sequence>
  64.             </xsd:complexType>
  65.             <xsd:simpleType name="***Enum">
  66.                 <xsd:restriction base="xsd:string">
  67.                     <xsd:enumeration value="FEMALE"></xsd:enumeration>
  68.                     <xsd:enumeration value="MALE"></xsd:enumeration>
  69.                 </xsd:restriction>
  70.             </xsd:simpleType>
  71.         </xsd:schema>
  72.     </wsdl:types>

  73.     <wsdl:message name="InsertUserRequest">
  74.         <wsdl:part element="tns:InsertUserRequest" name="request" />
  75.     </wsdl:message>
  76.     <wsdl:message name="InsertUserResponse">
  77.         <wsdl:part element="tns:InsertUserResponse" name="response" />
  78.     </wsdl:message>
  79.     <wsdl:message name="InsertUserFault">
  80.         <wsdl:part element="tns:InsertUserFault" name="fault"/>
  81.     </wsdl:message>
  82.     
  83.     <wsdl:portType name="UserManagement">
  84.         <wsdl:operation name="InsertUser">
  85.             <wsdl:input name="InsertUserRequest" message="tns:InsertUserRequest" />
  86.             <wsdl:output name="InsertUserResponse" message="tns:InsertUserResponse" />
  87.             <wsdl:fault name="InsertUserFault" message="tns:InsertUserFault"/>
  88.         </wsdl:operation>
  89.     </wsdl:portType>
  90.     <wsdl:binding name="UserManagementSOAP" type="tns:UserManagement">
  91.         <soap:binding style="document"
  92.             transport="" />
  93.         <wsdl:operation name="InsertUser">
  94.             <soap:operation soapAction="NewOperation" />
  95.             <wsdl:input>
  96.                 <soap:body use="literal" />
  97.             </wsdl:input>
  98.             <wsdl:output>
  99.                 <soap:body use="literal" />
  100.             </wsdl:output>
  101.             <wsdl:fault name="InsertUserFault">
  102.                 <soap:fault name="SoapFaultException" use="literal"/>
  103.             </wsdl:fault>
  104.         </wsdl:operation>
  105.     </wsdl:binding>
  106.     <wsdl:service name="UserManagement">
  107.         <wsdl:port binding="tns:UserManagementSOAP" name="UserManagementSOAP">
  108.             <soap:address location="" />
  109.         </wsdl:port>
  110.     </wsdl:service>
  111. </wsdl:definitions>

使用xsd修饰文件后的WSDL为:
UserManagement.wsdl
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <wsdl:definitions xmlns:soap=""
  3.     xmlns:tns="" xmlns:wsdl=""
  4.     xmlns:xsd="" name="UserManagement"
  5.     xmlns:mm1="InsertUser"
  6.     targetNamespace="">
  7.     <wsdl:types>
  8.         <xsd:schema targetNamespace="">
  9.             
  10.             <xsd:import namespace="InsertUser" schemaLocation="InsertUser.xsd"></xsd:import>
  11.             
  12.             <xsd:element name="InsertUserRequest" type="mm1:InsertUserRequest"/>

  13.             <xsd:element name="InsertUserResponse" type="mm1:InsertUserResponse"/>

  14.             <xsd:element name="InsertUserFault" type="mm1:InsertUserFault"/>

  15.         </xsd:schema>
  16.     </wsdl:types>

  17.     <wsdl:message name="InsertUserRequest">
  18.         <wsdl:part element="tns:InsertUserRequest" name="request" />
  19.     </wsdl:message>
  20.     <wsdl:message name="InsertUserResponse">
  21.         <wsdl:part element="tns:InsertUserResponse" name="response" />
  22.     </wsdl:message>
  23.     <wsdl:message name="InsertUserFault">
  24.         <wsdl:part element="tns:InsertUserFault" name="fault"/>
  25.     </wsdl:message>
  26.     
  27.     <wsdl:portType name="UserManagement">
  28.         <wsdl:operation name="InsertUser">
  29.             <wsdl:input name="InsertUserRequest" message="tns:InsertUserRequest" />
  30.             <wsdl:output name="InsertUserResponse" message="tns:InsertUserResponse" />
  31.             <wsdl:fault name="InsertUserFault" message="tns:InsertUserFault"/>
  32.         </wsdl:operation>
  33.     </wsdl:portType>
  34.     
  35.     
  36.     <wsdl:binding name="UserManagementSOAP" type="tns:UserManagement">
  37.         <soap:binding style="document"
  38.             transport="" />
  39.         <wsdl:operation name="InsertUser">
  40.             <soap:operation soapAction="NewOperation" />
  41.             <wsdl:input>
  42.                 <soap:body use="literal" />
  43.             </wsdl:input>
  44.             <wsdl:output>
  45.                 <soap:body use="literal" />
  46.             </wsdl:output>
  47.             <wsdl:fault name="InsertUserFault">
  48.                 <soap:fault name="SoapFaultException" use="literal"/>
  49.             </wsdl:fault>
  50.         </wsdl:operation>
  51.     </wsdl:binding>
  52.     
  53.     
  54.     <wsdl:service name="UserManagement">
  55.         <wsdl:port binding="tns:UserManagementSOAP" name="UserManagementSOAP">
  56.             <soap:address location="" />
  57.         </wsdl:port>
  58.     </wsdl:service>
  59. </wsdl:definitions>

InsertUser.xsd
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <schema xmlns=""
  3.     targetNamespace="InsertUser"
  4.     xmlns:ent="entity"
  5.     elementFormDefault="qualified">
  6.     <import namespace="entity"
  7.         schemaLocation="UserEntity.xsd" />

  8.     <complexType name="InsertUserRequest">
  9.         <sequence>
  10.             <element name="User" type="ent:User"/>
  11.         </sequence>
  12.     </complexType>

  13.     <complexType name="InsertUserResponse">
  14.         <sequence>
  15.             <element name="UserID" type="string"/>
  16.         </sequence>
  17.     </complexType>
  18.     
  19.     <complexType name="InsertUserFault"/>
  20. </schema>

UserEntity.xsd
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xs:schema elementFormDefault="qualified" xmlns:tns="entity"
  3.     targetNamespace="entity" xmlns:xs="">

  4.     <xs:complexType name="User">
  5.         <xs:sequence>
  6.             <xs:element name="UserIDString" type="xs:string" />
  7.             <xs:element name="UserNameString" type="xs:string" />
  8.             <xs:element name="******Enum" type="tns:***Enum" />

  9.             <!-- int===>java.int -->
  10.             <xs:element name="AgeInt" type="xs:int" />
  11.             <!-- integer===>java.BigInteger -->
  12.             <xs:element name="AgeInteger" type="xs:integer" />

  13.             <!-- time===>java.XMLGregorianCalendar -->
  14.             <!-- date===>java.XMLGregorianCalendar -->
  15.             <!-- dateTime===>java.XMLGregorianCalendar -->
  16.             <xs:element name="CreateTime" type="xs:time" />

  17.             <xs:element name="IsSleepBoolean" type="xs:boolean" />

  18.             <!-- maxOccurs="unbounded"===>java.List<> -->
  19.             <xs:element name="HobbyList" type="xs:string" maxOccurs="unbounded" />

  20.             <xs:element name="Goods" type="tns:Good" maxOccurs="unbounded" />

  21.             <xs:choice>
  22.                 <xs:element name="choice1" type="xs:string" />
  23.                 <xs:element name="choice2" type="xs:int" />
  24.             </xs:choice>
  25.         </xs:sequence>
  26.     </xs:complexType>

  27.     <xs:complexType name="Good">
  28.         <xs:sequence>
  29.             <xs:element name="GoodIDInt" type="xs:int" />
  30.             <xs:element name="GoodTypeString" type="xs:string" />
  31.         </xs:sequence>
  32.     </xs:complexType>

  33.     <xs:simpleType name="***Enum">
  34.         <xs:restriction base="xs:string">
  35.             <xs:enumeration value="FEMALE"></xs:enumeration>
  36.             <xs:enumeration value="MALE"></xs:enumeration>
  37.         </xs:restriction>
  38.     </xs:simpleType>
  39. </xs:schema>

build.properties
  1. projects.dir = ${basedir}
  2. cxf.home=${projects.dir}
  3. main.version=3.0
  4. gen.src.dir=${basedir}/gen-src


build.xml文件为:
  1. <?xml version="1.0" encoding="UTF-8"?>

  2. <project name="Test" default="publish.all" basedir=".">
  3.     <property file="build.properties"/>

  4.     <property name="project-name" value="Test"/>
  5.     <property name="build.classes" value="build/classes"/>

  6.     <path id="cxf.classpath">
  7.         <pathelement location="build/classes"/>
  8.         <fileset dir="${cxf.home}/lib">
  9.             <include name="**/*.jar"/>
  10.         </fileset>
  11.         <pathelement location="${build.classes}"/>
  12.     </path>

  13.     <target name="publish.all" depends="wsdl2java,zip-resources"/>
  14.     
  15.     <target name="clean-gen.src">
  16.         <delete dir="${gen.src.dir}"/>
  17.         <echo message="delete gen.src.dir ...."/>
  18.     </target>
  19.     
  20.     <!-- =================================
  21.          target: wsdl2java
  22.     ================================= -->
  23.     <target name="wsdl2java" depends="clean-gen.src">
  24.         <mkdir dir="${gen.src.dir}"/>
  25.         <!-- fork="true"
  26.         Ant的Javac任务的默认行为是调用运行Ant本身的任何JVM的标准编译器,
  27.         然而如果你想要单独地调用编译器,比如你要使用一个高级别的编译器,
  28.         你可以使用javac的fork属性
  29.         -->
  30.         <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true" classpathref="cxf.classpath">
  31.             <arg line="-d ${gen.src.dir}"/>
  32.             <arg line="-all"/>
  33.             <arg line="${basedir}\resources\wsdl\usermgr2\UserManagement.wsdl"/>
  34.         </java>
  35.     </target>

  36.     <!-- =============================================
  37.           target: zip resources
  38.     =============================================== -->
  39.     <target name="zip-resources" description="zip resources for publish">
  40.         <zip destfile="${basedir}/resources.zip">
  41.             <fileset dir="${basedir}/resources"/>
  42.         </zip>
  43.     </target>

  44. </project>


阅读(856) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~