微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XFire使用WSDL生成客户端代码

WSDL 如下:

 

 

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <wsdl:deFinitions targetNamespace="http://xfire.codehaus.org/BookService" xmlns:tns="http://xfire.codehaus.org/BookService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://demo.xfire.codehaus.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  3.   <wsdl:types>
  4. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://xfire.codehaus.org/BookService">
  5. <xsd:element name="getBooks">
  6. <xsd:complexType/>
  7. </xsd:element>
  8. <xsd:element name="getBooksResponse">
  9. <xsd:complexType>
  10. <xsd:sequence>
  11. <xsd:element maxOccurs="1" minOccurs="1" name="book" nillable="true" type="ns1:Book">
  12. <xsd:annotation>
  13. <xsd:documentation>All books.</xsd:documentation>
  14. </xsd:annotation>
  15. </xsd:element>
  16. </xsd:sequence>
  17. </xsd:complexType>
  18. </xsd:element>
  19. </xsd:schema>
  20. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.xfire.codehaus.org">
  21. <xsd:complexType name="Book">
  22. <xsd:sequence>
  23. <xsd:element minOccurs="0" name="author" nillable="true" type="xsd:string"/>
  24. <xsd:element minOccurs="0" name="isbn" nillable="true" type="xsd:string"/>
  25. <xsd:element minOccurs="0" name="title" nillable="true" type="xsd:string"/>
  26. </xsd:sequence>
  27. </xsd:complexType>
  28. </xsd:schema>
  29.   </wsdl:types>
  30.   <wsdl:message name="getBooksRequest">
  31.     <wsdl:part name="parameters" element="tns:getBooks">
  32.     </wsdl:part>
  33.   </wsdl:message>
  34.   <wsdl:message name="getBooksResponse">
  35.     <wsdl:part name="parameters" element="tns:getBooksResponse">
  36.     </wsdl:part>
  37.   </wsdl:message>
  38.   <wsdl:portType name="BookServicePortType">
  39. <wsdl:documentation/>
  40.     <wsdl:operation name="getBooks">
  41. <wsdl:documentation/>
  42.       <wsdl:input name="getBooksRequest" message="tns:getBooksRequest">
  43.     </wsdl:input>
  44.       <wsdl:output name="getBooksResponse" message="tns:getBooksResponse">
  45.     </wsdl:output>
  46.     </wsdl:operation>
  47.   </wsdl:portType>
  48.   <wsdl:binding name="BookServiceHttpBinding" type="tns:BookServicePortType">
  49.     <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  50.     <wsdl:operation name="getBooks">
  51.       <wsdlsoap:operation soapAction=""/>
  52.       <wsdl:input name="getBooksRequest">
  53.         <wsdlsoap:body use="literal"/>
  54.       </wsdl:input>
  55.       <wsdl:output name="getBooksResponse">
  56.         <wsdlsoap:body use="literal"/>
  57.       </wsdl:output>
  58.     </wsdl:operation>
  59.   </wsdl:binding>
  60.   <wsdl:service name="BookService">
  61.     <wsdl:port name="BookServiceHttpPort" binding="tns:BookServiceHttpBinding">
  62.       <wsdlsoap:address location="http://hehui:8080/xfire/services/BookService"/>
  63.     </wsdl:port>
  64.   </wsdl:service>
  65. </wsdl:deFinitions>

 

 

build.xml 如下:

 

  1. <?xml version="1.0"?>
  2. <project name="wsgen" default="wsgen" basedir=".">
  3. <taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" 
  4.      />
  5.   <target name="wsgen" description="remove all built files">
  6.     <wsgen outputDirectory="."
  7.   wsdl="BookService.wsdl" package="net" overwrite="true"/>
  8.       </target>
  9. </project>

 

 

运行ant  即可生成客户端代码

 

使用生成代码访问webservice:

 

 

 

 

  1. import net.BookServiceClient;
  2. import org.codehaus.xfire.demo.Book;
  3. public class XFireClient2 {
  4.     /**
  5.      * @param args
  6.      */
  7.     public static void main(String[] args) {
  8.         // Todo Auto-generated method stub
  9.         BookServiceClient client = new BookServiceClient();
  10.         Book book = client.getBookServiceHttpPort().getBooks();
  11.         System.out.println(book.getTitle().getValue());
  12.     }
  13. }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐