加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

XFire使用WSDL生成客户端代码

发布时间:2020-12-17 02:39:59 所属栏目:安全 来源:网络整理
导读:WSDL 如下: ? ? ? xml ? version = "1.0" ? encoding = "UTF-8" ? wsdl:definitions ? targetNamespace = "http://xfire.codehaus.org/BookService" ? xmlns:tns = "http://xfire.codehaus.org/BookService" ? xmlns:wsdlsoap = "http://schemas.xmlsoap.or

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. }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读