- 创建WSDL文件, 从WSDL文件生成代码.(本文的方式)
- 从POJO(Plain Old Java Object)开始,注释POJO,通过注释自动创建WSDL文件,同时生成相关代码.(<<Web Service Eclipse CXF集成.doc>>中描述的就是从POJO开始开发的方法.)
实战服务设计
- 图书订单Service
服务的输出(BookOrderResponse).
- 图书订单(BookOrder)的信息:
accountNumber 帐号
shipAddress 发货地址
billAddress 帐单地址
book 图书订单
total 总价
图书的信息book包括:
Title 书名
Quantity 订单数目
wholesale-price 批发价
发货地址和帐单地址类型的基础类型为Address包括:
Name 地址名称
Street 街道(可以多行)
City 城市
Country 国家
派生的地址类别UKAddress还包括:
Postcode 邮政编码
派生的地址类别USAddress还包括:
State 州
Zip 邮政编码
限制的地址BriefUSAddress只包括下面信息(限制于USAddress):
Name 名字
Street 街道
Zip 邮政编码
- 服务的输出
Return 返回的状态(成功或者失败)
Returninfo 返回的信息(可以多行)
图书订单服务的WSDL
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="cxfstp04Service" targetNamespace="http://www.example.org/cxfstp04/" xmlns:ns1="http://www.example.org/cxfstp04/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:types> <xsd:schema targetNamespace="http://www.example.org/cxfstp04/"> <xsd:element name="BookOrder" type="ns1:BookOrder"/> <xsd:element name="BookOrderResponse" type="ns1:BookOrderResponse"/> <xsd:complexType name="Address"> <xsd:sequence> <xsd:element name="name" type="xsd:string"></xsd:element> <xsd:element name="street" type="xsd:string" maxOccurs="unbounded"> </xsd:element> <xsd:element name="city" type="xsd:string"></xsd:element> <xsd:element name="country" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Book"> <xsd:sequence> <xsd:element name="title" type="xsd:string"></xsd:element> <xsd:element name="quantity" type="xsd:unsignedShort"></xsd:element> <xsd:element name="wholesale-price" type="xsd:float"></xsd:element> </xsd:sequence> </xsd:complexType> <xsd:complexType name="UKAddress"> <xsd:complexContent> <xsd:extension base="ns1:Address"> <xsd:sequence> <xsd:element name="postcode" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="USAddress"> <xsd:complexContent> <xsd:extension base="ns1:Address"> <xsd:sequence> <xsd:element name="state" type="xsd:string"> </xsd:element> <xsd:element name="zip" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="BriefUSAddress"> <xsd:complexContent> <xsd:restriction base="ns1:USAddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"> </xsd:element> <xsd:element name="street" type="xsd:string"> </xsd:element> <xsd:element name="zip" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> <xsd:simpleType name="Total"> <xsd:restriction base="xsd:float"> <xsd:maxExclusive value="100000"></xsd:maxExclusive> <xsd:minExclusive value="0"></xsd:minExclusive> <xsd:pattern value="[0-9]+\.[0-9]{2}"></xsd:pattern> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="BookOrder"> <xsd:sequence> <xsd:element name="accountName" type="xsd:string"></xsd:element> <xsd:element name="accountNumber" type="xsd:unsignedShort"> </xsd:element> <xsd:element name="shipAddress" type="ns1:Address"> </xsd:element> <xsd:element name="billAddress" type="ns1:Address"> </xsd:element> <xsd:element name="book" type="ns1:Book"></xsd:element> <xsd:element name="total" type="ns1:Total"></xsd:element> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"></xsd:attribute> </xsd:complexType> <xsd:complexType name="BookOrderResponse"> <xsd:sequence> <xsd:element minOccurs="0" name="return" type="xsd:string"/> <xsd:element name="returninfo" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:schema> </wsdl:types> <wsdl:message name="BookOrderResponse"> <wsdl:part name="result" element="ns1:BookOrderResponse"> </wsdl:part> </wsdl:message> <wsdl:message name="BookOrder"> <wsdl:part name="parameters" element="ns1:BookOrder"> </wsdl:part> </wsdl:message> <wsdl:portType name="OrderBook"> <wsdlperation name="OrderBookOper"> <wsdl:input name="BookOrder" message="ns1:BookOrder"> </wsdl:input> <wsdlutput name="BookOrderResponse" message="ns1:BookOrderResponse"> </wsdlutput> </wsdl:operation> </wsdl:portType> <wsdl:binding name="cxfstp04ServiceBinding" type="ns1:OrderBook"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="OrderBookOper"> <soap:operation soapAction="" style="document"/> <wsdl:input name="BookOrder"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="BookOrderResponse"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="cxfstp04Service"> <wsdl:port name="OrderBookPort" binding="ns1:cxfstp04ServiceBinding"> <soap:address location="http://localhost:9090/OrderBook"/> </wsdl:port> </wsdl:service> </wsdl:definitions> |
Eclipse WSDL设计图书订单服务Schema描述
WSDL定义 |
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="cxfstp04Service" targetNamespace="http://www.example.org/cxfstp04/" xmlns:ns1="http://www.example.org/cxfstp04/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:types> <xsd:schema targetNamespace="http://www.example.org/cxfstp04/"> <xsd:element name="BookOrder" type="ns1:BookOrder"/> <xsd:element name="BookOrderResponse" type="ns1:BookOrderResponse"/> … </xsd:schema> |
地址类型Address(通用类型),包括的元素:
|
<xsd:complexType name="Address"> <xsd:sequence> <xsd:element name="name" type="xsd:string"></xsd:element> <xsd:element name="street" type="xsd:string" maxOccurs="unbounded"> </xsd:element> <xsd:element name="city" type="xsd:string"></xsd:element> <xsd:element name="country" type="xsd:string"></xsd:element> </xsd:sequence> </xsd:complexType> |
美国地址类型(派生于Address),添加下面的元素:
|
<xsd:complexType name="USAddress"> <xsd:complexContent> <xsd:extension base="ns1:Address"> <xsd:sequence> <xsd:element name="state" type="xsd:string"> </xsd:element> <xsd:element name="zip" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> |
简略美国地址类型(限制于USAddress),包括的元素:
|
<xsd:complexType name="BriefUSAddress"> <xsd:complexContent> <xsd:restriction base="ns1:USAddress"> <xsd:sequence> <xsd:element name="name" type="xsd:string"> </xsd:element> <xsd:element name="street" type="xsd:string"> </xsd:element> <xsd:element name="zip" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:restriction> </xsd:complexContent> </xsd:complexType> |
英国地址:(派生于Address),添加下面的元素:
|
<xsd:complexType name="UKAddress"> <xsd:complexContent> <xsd:extension base="ns1:Address"> <xsd:sequence> <xsd:element name="postcode" type="xsd:string"> </xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> |
书:包括元素:
|
<xsd:complexType name="Book"> <xsd:sequence> <xsd:element name="title" type="xsd:string"></xsd:element> <xsd:element name="quantity" type="xsd:unsignedShort"></xsd:element> <xsd:element name="wholesale-price" type="xsd:float"></xsd:element> </xsd:sequence> </xsd:complexType> |
总价(简单类型)
|
<xsd:simpleType name="Total"> <xsd:restriction base="xsd:float"> <xsd:maxExclusive value="100000"></xsd:maxExclusive> <xsd:minExclusive value="0"></xsd:minExclusive> <xsd:pattern value="[0-9]+\.[0-9]{2}"></xsd:pattern> </xsd:restriction> </xsd:simpleType> |
订单,包括元素
|
<xsd:complexType name="BookOrder"> <xsd:sequence> <xsd:element name="accountName" type="xsd:string"></xsd:element> <xsd:element name="accountNumber" type="xsd:unsignedShort"> </xsd:element> <xsd:element name="shipAddress" type="ns1:Address"> </xsd:element> <xsd:element name="billAddress" type="ns1:Address"> </xsd:element> <xsd:element name="book" type="ns1:Book"></xsd:element> <xsd:element name="total" type="ns1:Total"></xsd:element> </xsd:sequence> <xsd:attribute name="orderDate" type="xsd:date"></xsd:attribute> </xsd:complexType> |
订单返回,包括元素
|
<xsd:complexType name="BookOrderResponse"> <xsd:sequence> <xsd:element minOccurs="0" name="return" type="xsd:string"/> <xsd:element name="returninfo" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> |
图书订单服务实例
输入
|
<ns2:BookOrder xmlns:ns2="http://www.example.org/cxfstp04/" orderDate="2007-09-08Z"> <accountName>Amazon.com</accountName> <accountNumber>923</accountNumber> <shipAddress xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:UKAddress"> <name>Amazon.co.uk</name> <street>line1: Ridgmont Road</street> <street>line2: Ridgmont Road</street> <city>Bedford</city> <country>United Kingdom</country> <postcode>MK43 0ZA</postcode> </shipAddress> <billAddress xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:BriefUSAddress"> <name>Amazon.com</name> <street>line1: 1516 2nd Ave</street> <street>line2: 1516 2nd Ave</street> <street>line3: 1516 2nd Ave</street> <zip>90952</zip> </billAddress> <book> <title>Java Web Services</title> <quantity>300</quantity> <wholesale-price>24.99</wholesale-price> </book> <total>8997.0</total> </ns2:BookOrder> |