kapok

垃圾桶,嘿嘿,我藏的这么深你们还能找到啊,真牛!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  455 随笔 :: 0 文章 :: 76 评论 :: 0 Trackbacks
http://www-128.ibm.com/developerworks/cn/webservices/ws-uwsdl/part2/index.html
发布和查找 WSDL 服务描述的用法个案研究

Peter Brittenham
资深软件工程师, IBM 新兴技术
2001 年 9 月

如这个系列的第 1 篇文章说明的那样,“Web 服务描述语言”(Web Services Description Language(WSDL))的多功能性使得在 UDDI 注册中心使用它更加复杂。在本文,即本系列第 2 部分中,Peter 使用各种 WSDL 用法个案研究来实现将 WSDL 映射到 UDDI 环境的过程。

如本系列的第 1 部分所述(请参阅 参考资料),一个完整的 WSDL 服务描述由服务接口和服务实现组成。这些服务描述中的每一个都可以驻留在不同的物理 WSDL 文档中。

本系列的这一部分包含在“UDDI 注册中心”发布和查找完整的 WSDL 服务描述的用法个案研究。对于每一个用法个案研究,我将描述一个在 UDDI 注册中心发布完整的 WSDL 服务定义的方法。对这些方法的描述根据的是 UDDI 优化方法文档中的过程以及“UDDI 程序员的 API 规范”和“UDDI 数据结构参考大全”中定义的用法约定(请参阅 参考资料)。

个案研究 1:没有服务实现的服务接口
当服务接口提供者将 WSDL 服务接口定义作为 tModel 发布时,将可以从任意 UDDI businessService 引用这个 tModel。这个个案研究展示如何发布一个带有对 tModel(此 tModel 与 WSDL 服务接口相关联)的引用的 businessService。在这个个案研究中,UDDI businessService 与 WSDL 服务实现定义无关。可以使用 UDDI 优化方法文档中描述的过程实现这个个案研究。

WSDL 服务接口定义
服务接口文档包含所有的 WSDL 类型、message、portType 和 binding 元素。在这个个案研究中,Web 服务包含一个操作,使用 SOAP 指定绑定。这个示例并不包括 types 元素,因为这个用法个案研究不要求消息的数据类型定义。

清单 1包含一个简单服务接口文档示例。突出显示的域将在 UDDI 数据实体中被引用。

清单 1: 个案研究 1 简单服务接口文档

<?xml version="1.0"?>
<definitions name="StockQuoteService-interface"
  targetNamespace="http://www.getquote.com/StockQuoteService-interface"
  xmlns:tns="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
    Standard WSDL service interface definition for a stock quote service.
  </documentation>

  <message name="SingleSymbolRequest">
    <part name="symbol" type="xsd:string"/>
  </message>

  <message name="SingleSymbolQuoteResponse">
    <part name="quote" type="xsd:string"/>
  </message>
 
  <portType name="SingleSymbolStockQuoteService">
    <operation name="getQuote">
      <input message="tns:SingleSymbolRequest"/>
      <output message="tns:SingleSymbolQuoteResponse"/>
    </operation>
  </portType>

  <binding name="SingleSymbolBinding"
           type="tns:SingleSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuote">
      <soap:operation soapAction="http://www.getquote.com/GetQuote"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>  
</definitions>

发布 UDDI tModel
WSDL 服务接口描述由服务接口提供者发布。发布了这个文档后,服务提供者才可以发布一个引用服务接口的 businessService。这个服务接口被作为 tModel 发布,将包含一个对 WSDL 服务接口文档的引用。

清单 2包含发布上面列出的服务接口时创建的 tModel。

清单 2:个案研究 1 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService-interface</name>

  <description xml:lang="en">
    Standard WSDL service interface definition for a stock quote service.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
      http://www.getquote.com/services/SQS-interface.wsdl#SingleSymbolBinding
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>

发布 UDDI businessService
实现这个服务接口的服务提供者可以发布一个引用与服务接口相关联的 tModel 的 businessService 描述。不必使用 WSDL 指定服务实现的服务描述。

清单 3:个案研究 1 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
  <name>StockQuoteService</name>

  <description xml:lang="en">
    Stock Quote Service
  </description>

  <bindingTemplates>
    <bindingTemplate bindingKey="" serviceKey="">
      <description>
        Single Symbol Service
      <description>
      <accessPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
  </bindingTemplates>

  <categoryBag>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</businessService>

构建一个 WSDL 服务实现文档
既然 UDDI businessService 不是根据 WSDL 服务实现文档创建的,那么需要 WSDL 的工具或运行时组件将不得不根据 businessService 和被它的 bindingTemplates 引用的 tModel 的内容构建一个 WSDL 文档。

清单 4包含一个 WSDL 服务实现文档,该文档是根据这个个案研究的 UDDI businessService 的内容创建的。值显示在图表键中。

清单 4:个案研究 1 根据 UDDI businessService 创建的 WSDL 服务实现
<?xml version="1.0"?>
<definitions name="StockQuoteService"
  xmlns:interface1="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <import namespace="http://www.getquote.com/StockQuoteService-interface"
     location="http://www.getquote.com/wsdl/SQS-interface.wsdl"/>

  <service name="StockQuoteService">
    <documentation>Stock Quote Service</documentation>
    
    <port name="StockQuoteServicePort"
        binding="interface1:SingleSymbolBinding">
      <documentation>Single Symbol Service</documentation>
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
  </service>
</definitions>

关键字:

Definitions― definitions 元素的 name 属性根据 businessService 名称设置。XML 模式、WSDL、SOAP 绑定、HTTP 绑定和 MIME 绑定的 XML 名称空间引用被添加到 definitions 元素。
Import― 一个 import 元素是为一个引用 WSDL 服务接口文档的 tModel 创建的。tModel 关键字被用于获取 tModel 详细信息。tModel 包含引用 WSDL 服务接口文档的 overviewURL。namespace 属性使用 WSDL 服务接口文档中的 targetNamespace 来设置。location 属性使用与服务接口定义相关联的 tModel 内 overviewURL 中的值来设置。对于每个 import 元素,XML 名称空间引用都要被添加到 definitions 元素中,方法是使用服务接口文档中的 targetNamespace。
Service― service 元素的 name 属性根据 businessService 名称设置。因为服务名称是一个 NCName,所以必须修改 businessService 名称以获取适当的 WSDL 服务名称。service 元素中的 documentation 元素根据 businessService 描述设置。
Port― 一个 port 元素是为 businessService(此 businessService 引用使用 WSDL 描述的服务)中的一个 bindingTemplate 创建的。port 元素的 name 属性被设置为服务名称,并附加字符串“Port”。为了设置 binding 属性,绑定引用是从 tModel 中的 overviewURL 获取的。如果没有指定绑定是在 overviewURL 上,那么 WSDL 服务接口中的第 1 个绑定被用于设置绑定名称。因为 binding 属性是一个 QName,所以用服务接口引用的 XML 名称空间规范作为绑定名称的前缀。如果 bindingTemplate 包含一个描述,那么它将被用于设置 port 元素中的 documentation 元素。port 元素中的 extension 元素是根据绑定类型创建的。对于一个 SOAP 绑定,使用 soap:address 元素。extension 元素的 location 属性根据 bindingTemplate 中的 accessPoint 设置。

个案研究 2:带有一个服务接口文档的服务实现
服务接口可以由一个人来开发,然后由另一个人来实现和引用。对于那些只对 WSDL 服务描述进行操作的一组工具或运行时组件,WSDL 服务实现文档将包含对 WSDL 服务接口文档的一个引用。在这个个案研究中,服务实现文档只引用一个 WSDL 服务接口文档。

WSDL 服务接口定义
这个个案研究的服务接口定义与 UDDI 优化方法文档中描述的那个服务接口定义一致。服务接口文档包含所有的 WSDL 类型、message、portType 和 binding 元素。

清单 5包含一个简单服务接口文档示例。这个文档中描述的服务包含一个操作,使用 SOAP 指定绑定。突出显示的域将在 UDDI 数据实体中被引用。

清单 5:个案研究 2 WSDL 服务接口文档
<?xml version="1.0"?>
<definitions name="StockQuoteService-interface"
  targetNamespace="http://www.getquote.com/StockQuoteService-interface"
  xmlns:tns="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
   Standard service interface definition for a stock quote service.
  </documentation>

  <message name="SingleSymbolRequest">
    <part name="symbol" type="xsd:string"/>
  </message>

  <message name="SingleSymbolQuoteResponse">
    <part name="quote" type="xsd:string"/>
  </message>
 
  <portType name="SingleSymbolStockQuoteService">
    <operation name="getQuote">
      <input message="tns:SingleSymbolRequest"/>
      <output message="tns:SingleSymbolQuoteResponse"/>
    </operation>
  </portType>

  <binding name="SingleSymbolBinding"
           type="tns:SingleSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuote">
      <soap:operation soapAction="http://www.getquote.com/GetQuote"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>  
</definitions>

发布 UDDI tModel
必须在服务接口提供者发布服务接口描述之后,才可以发布服务实现描述。这个服务接口被作为 tModel 发布。这个 tModel 将包含对 WSDL 服务接口文档的引用。

清单 6包含发布上面列出的服务接口时创建的 tModel。

清单 6:个案研究 2 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService-interface</name>

  <description xml:lang="en">
    Standard service interface definition for a stock quote service.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
      http://www.getquote.com/services/SQS-interface.wsdl#SingleSymbolBinding
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>

WSDL 服务实现定义
服务实现文档包含一个引用服务接口文档的 import 元素和一个包含对 Web 服务位置的引用的 service 元素。 清单 7包含这种类型 WSDL 文档的一个示例

清单 7:个案研究 2 WSDL 服务实现定义
<?xml version="1.0"?>
<definitions name="StockQuoteService"
  targetNamespace="http://www.getquote.com/StockQuoteService"
  xmlns:interface="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <import namespace="http://www.getquote.com/StockQuoteService-interface"
     location="http://www.getquote.com/wsdl/SQS-interface.wsdl"/>

  <service name="StockQuoteService">
    <documentation>Stock Quote Service</documentation>
    
    <port name="SingleSymbolService"
        binding="interface:SingleSymbolBinding">
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
  </service>
</definitions>

发布 UDDI businessService
WSDL 服务实现描述由服务提供者发布。服务实现被作为 businessService 发布。与服务接口相关联的 tModel 被 businessService 内的 bindingTemplate 引用。

这个发布服务实现的方法不是在 UDDI 优化方法文档中定义的。UDDI 优化方法文档第 7 页的“Publishing Service Implementations”包含对如何根据 WSDL 服务实现文档创建 businessService 的描述。

清单 8包含根据上面列出的服务实现创建的一个 businessService 的示例。

清单 8:个案研究 2 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
  <name>StockQuoteService</name>

  <description xml:lang="en">
    Stock Quote Service
  </description>

  <bindingTemplates>
    <bindingTemplate bindingKey="" serviceKey="">
      <accesssPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
          <instanceDetails>
            <overviewURL>
              http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
            </overviewURL>
          </instanceDetails>
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
  </bindingTemplates>
    
  <categoryBag>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</businessService>

个案研究 3:带有多个服务接口文档的服务实现
一个服务提供者可能决定开发一个实现多个服务接口定义的 Web 服务。这个 Web 服务的 WSDL 服务实现文档将包含对全部服务接口文档的引用。对服务接口文档的每个引用都是用服务实现文档中的 import 元素表示。

WSDL 服务接口定义
对于这个个案研究,有两个不同的服务接口。这两个服务接口可以由同一个服务接口提供者发布,也可以由不同的服务接口提供者发布。每个服务接口文档包含不同的目标名称空间、端口类型和绑定。而且,每个 SOAP 绑定引用一个不同的 SOAP 服务。

下面的图包含一个服务的服务接口定义,这个服务要求一个股票符号作为输入消息,一个股票报价作为响应。

清单 9:个案研究 3 第一个 WSDL 服务接口
<?xml version="1.0"?>
<definitions name="StockQuoteService-SingleSymbol-interface"
  targetNamespace="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
  xmlns:tns="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
    Standard service interface definition for a stock quote service that
    has only one symbol as an input parameter.
  </documentation>

  <message name="SingleSymbolRequest">
    <part name="symbol" type="xsd:string"/>
  </message>

  <message name="SingleSymbolQuoteResponse">
    <part name="quote" type="xsd:string"/>
  </message>
 
  <portType name="SingleSymbolStockQuoteService">
    <operation name="getQuote">
      <input message="tns:SingleSymbolRequest"/>
      <output message="tns:SingleSymbolQuoteResponse"/>
    </operation>
  </portType>

  <binding name="SingleSymbolBinding"
           type="tns:SingleSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuote">
      <soap:operation soapAction="http://www.getquote.com/GetQuote"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:single-symobl-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>
</definitions>

清单 10包含一个服务接口定义,该定义可以拥有多个股票符号作为输入消息,多个股票报价作为响应。这个服务接口包含自己的消息(message)、端口类型(portType)和绑定(binding)规范。

清单 10:个案研究 3 第二个 WSDL 服务接口
<?xml version="1.0"?>
<definitions name="StockQuoteService-MultSymbol-interface"
  targetNamespace="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
  xmlns:tns="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:xsd1="http://http://www.getquote.com/StockQuoteService/schema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
    Standard service interface definition for a stock quote service that 
    can receive a request that contains multiple symbols.
  </documentation>

  <types>
    <schema targetNamespace="http://www.getquote.com/StockQuoteService/schema"
      xmlns="http://www.w3.org/2001/XMLSchema"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">  
      <complexType name="ArrayOfString">
        <complexContent>
          <restriction base="soapenc:Array">
            <attribute ref=soapenc:arrayType
                       wsdl:arrayType="xsd:string[]"/>
          </restriction>
        </complexContent>
      </compextType>
    </schemas>
  </types>
  
  <message name="MultSymbolRequest">
    <part name="symbols" type="xsd1:ArrayOfString"/>
  </message>
  <message name="MultSymbolQuoteResponse">
    <part name="quotes" type="xsd1:ArrayOfString"/>
  </message>

  <portType name="MultSymbolStockQuoteService">
    <operation name="getQuotes">
      <input message="tns:MultSymbolRequest"/>
      <output message="tns:MultSymbolQuoteResponse"/>
    </operation>
  </portType>

  <binding name="MultSymbolBinding"
           type="tns:MultSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuotes">
      <soap:operation soapAction="http://www.getquote.com/GetQuotes"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:mult-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:mult-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>

发布 UDDI tModel
这个个案研究的两个 WSDL 服务接口都将在 UDDI 注册中心被作为单独的 tModel 发布。既然每个服务接口只包含一个绑定,overviewURL 就不需要引用一个特定绑定。 清单 11包含描述第一个服务接口定义的 tModel。

清单 11:个案研究 3 第一个 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService-SingleSymbol-interface</name>

  <description xml:lang="en">
    Standard service interface definition for a stock quote service that
    has only one symbol as an input parameter.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
      http://www.getquote.com/services/SQS-SingleSymbol-interface.wsdl
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>

清单 12包含第二个服务接口定义的 tModel

清单 12:个案研究 3 第二个 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService-MultSymbol-interface</name>

  <description xml:lang="en">
    Standard service interface definition for a stock quote service that 
    can receive a request that contains multiple symbols.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
      http://www.getquote.com/services/SQS-MultSymbol-interface.wsdl
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>

WSDL 服务实现定义
这个个案研究的 WSDL 服务实现文档将包含两个 import 元素。每个 import 元素将引用其中一个服务接口文档。这个文档还包含至少两个 port 元素。每个 port 元素从其中一个服务接口文档的内部引用一个绑定。

清单 13:个案研究 3 WSDL 服务实现
<definitions name="StockQuoteService"
  targetNamespace="http://www.getquote.com/StockQuoteService"
  xmlns:single="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
  xmlns:mult="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <import 
   namespace="http://www.getquote.com/StockQuoteService-SingleSymbol-interface"
   location="http://www.getquote.com/wsdl/SQS-SingleSymbol-interface.wsdl"/>

  <import 
    namespace="http://www.getquote.com/StockQuoteService-MultSymbol-interface"
    location="http://www.getquote.com/wsdl/SQS-MultSymbol-interface.wsdl"/>

  <service name="StockQuoteService">
    <documentation>Stock Quote Service</documentation>
    
    <port name="SingleSymbolService"
        binding="single:SingleSymbolBinding">
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
    
    <port name="MultSymbolService" 
        binding="mult:MultSymbolBinding">
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
  </service>
</definitions>

发布 UDDI businessService
对于这个个案研究,服务提供者开发了一个对两个服务接口都实现的服务。服务实现描述由服务提供者作为 UDDI businessService 发布。因为一个服务实现使用不同的 import 元素引用多个服务接口,所以 businessService 中的每个 bindingTemplate 将引用不同的 tModel。

这个发布服务实现的方法不是在 UDDI 优化方法文档中定义的。UDDI 优化方法文档第 7 页的“Publishing Service Implementations”包含对如何根据 WSDL 服务实现文档创建 businessService 的描述。

清单 14包含根据上面列出的服务实现创建的一个 businessService 的示例

清单 14:个案研究 3 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
  <name>StockQuoteService</name>

  <description xml:lang="en">
    Stock Quote Service
  </description>

  <bindingTemplates>
    <bindingTemplate bindingKey="" serviceKey="">
      <accesssPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo tModelKey="[tModel Key for Service Interface 1]">
          <instanceDetails>
            <overviewURL>
              http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
            </overviewURL>
          </instanceDetails>
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
    
    <bindingTemplate bindingKey="" serviceKey="">
      <accesssPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo tModelKey="[tModel Key for Service Interface 2]">
          <instanceDetails>
            <overviewURL>
              http://www.getquote.com/services/SQS.wsdl#MultSymbolService
            </overviewURL>
          </instanceDetails>
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
  </bindingTemplates>

  <categoryBag>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</businessService>

个案研究 4:单个 WSDL 文档
如果服务接口提供者和服务提供者是同一个人,那么一个 WSDL 文档就可用于定义一个完整的 WSDL 服务描述。这个个案研究的目的是展示 UDDI businessService 和 tModel 可以从它们各自的 overviewURL 元素引用相同的文档。

一个 WSDL 文档被既作为 UDDI tModel,又作为 businessService 发布。这些数据实体都将包含对同一个 WSDL 文档的引用。

单个 WSDL 服务定义
清单 15包含一个包含完整的服务定义的 WSDL 文档示例。这个文档包含完整地描述一个 Web 服务所需的全部 WSDL 元素。将服务接口定义和服务实现定义组合成一个 WSDL 文档即可形成这样一个文档。

清单 15:个案研究 4 单个文档中完整的 WSDL 服务定义
<?xml version="1.0"?>
<definitions name="StockQuoteService"
  targetNamespace="http://www.getquote.com/StockQuoteService"
  xmlns:tns="http://www.getquote.com/StockQuoteService"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
   Service definition for a complete stock quote service.
  </documentation>

  <message name="SingleSymbolRequest">
    <part name="symbol" type="xsd:string"/>
  </message>

  <message name="SingleSymbolQuoteResponse">
    <part name="quote" type="xsd:string"/>
  </message>
 
  <portType name="SingleSymbolStockQuoteService">
    <operation name="getQuote">
      <input message="tns:SingleSymbolRequest"/>
      <output message="tns:SingleSymbolQuoteResponse"/>
    </operation>
  </portType>

  <binding name="SingleSymbolBinding"
           type="tns:SingleSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuote">
      <soap:operation soapAction="http://www.getquote.com/GetQuote"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:single-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:single-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>  

  <service name="StockQuoteService">
    <documentation>Stock Quote Service</documentation>
    
    <port name="SingleSymbolService"
        binding="tns:SingleSymbolBinding">
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
  </service>
</definitions>

       

发布 UDDI tModel
当 UDDI tModel 被发布时,它将包含对 WSDL 文档(该文档包含完整的服务描述)的引用。创建这个 tModel 使用的过程与为 WSDL 服务接口定义所定义的过程一样。尽管 overviewURL 将包含对一个完整的 WSDL 文档的引用,tModel 仍是只引用这个文档中的绑定。这意味着 tModel 不引用 service 和 port 元素。

清单 16:个案研究 4 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService</name>

  <description xml:lang="en">
    Service definition for a complete stock quote service.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
     http://www.getquote.com/services/SQS.wsdl
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>
        
       

发布 UDDI businessService
UDDI businessService 是根据完整的 WSDL 服务描述创建的,使用的过程与 WSDL 服务实现文档所用的一样。

清单 17:个案研究 4 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
  <name>StockQuoteService</name>

  <description xml:lang="en">
    Stock Quote Service
  </description>

  <bindingTemplates>
    <bindingTemplate bindingKey="" serviceKey="">
      <accesssPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo tModelKey="[tModel Key for Service Interface]">
          <instanceDetails>
            <overviewURL>
              http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
            </overviewURL>
          </instanceDetails>
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
  </bindingTemplates>

  <categoryBag>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</businessService>
       

个案研究 5:引用另一个服务接口的服务接口
服务接口提供者可以开发仅包含 types、message 和 portType 元素的服务接口。然后这个服务接口可被其它的服务接口提供者用来为服务接口指定特定绑定。只有包含这些绑定的服务接口才可被作为 UDDI tModel 发布。仅包含 types、message 和 portType 元素的 WSDL 服务接口无法被作为 UDDI tModel 发布。UDDI tModel 只可引用至少包含一个 binding 元素的 WSDL 服务接口。

带有 messages 和 portTypes 的 WSDL 服务接口定义
服务接口提供者开发了仅包含 messages 和 portTypes 的服务接口。服务接口不必包含绑定规范。

清单 18:个案研究 5 带有 messages 和 portType 的 WSDL 服务接口定义
<?xml version="1.0"?>
<definitions name="StockQuoteService-interface"
  targetNamespace="http://www.getquote.com/StockQuoteService-interface"
  xmlns:tns="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
    Standard service interface definition for a stock quote service
    without any bindings.
  </documentation>

  <message name="SingleSymbolRequest">
    <part name="symbol" type="xsd:string"/>
  </message>

  <message name="SingleSymbolQuoteResponse">
    <part name="quote" type="xsd:string"/>
  </message>
 
  <portType name="SingleSymbolStockQuoteService">
    <operation name="getQuote">
      <input message="tns:SingleSymbolRequest"/>
      <output message="tns:SingleSymbolQuoteResponse"/>
    </operation>
  </portType>
</definitions>
       

带有多个绑定(bindings)的 WSDL 服务接口定义
服务提供者可以实现仅包含 message 和 portType 元素的现有服务接口定义。这个实现会要求一个特定绑定,这个绑定由服务提供者指定。这个绑定规范被放在一个服务接口文档中,该文档还将包含对原始服务接口文档的引用。

清单 19:个案研究 5 带有多个绑定的 WSDL 服务接口定义
<?xml version="1.0"?>
<definitions name="StockQuoteService-binding"
  targetNamespace="http://www.getquote.com/StockQuoteService-binding"
  xmlns:interface="http://www.getquote.com/StockQuoteService-interface"
  xmlns:xsd=" http://www.w3.org/2001/XMLSchema "
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <documentation>
    Service interface binding definition for a stock quote service.
  </documentation>

  <import namespace="http://www.getquote.com/StockQuoteService-interface/"
          location="http://www.getquote.com/SQS-interface.wsdl">

  <binding name="SingleSymbolBinding"
           type="interface:SingleSymbolStockQuoteService">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getQuote">
      <soap:operation soapAction="http://www.getquote.com/GetQuote"/>
      <input>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
        <soap:body use="encoded"
            namespace="urn:single-symbol-stock-quotes"
            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
    </operation>
  </binding>  
</definitions>

发布带有多个绑定的服务接口的 UDDI tModel
带有多个绑定的服务接口的 tModel 可作为 tModel 被发布。这个 tModel 将只引用包含绑定定义的 WSDL 服务接口文档。必须检索这个文档来确定包含服务接口定义其余内容的文档。完整的服务接口定义是根据原始服务接口文档中的 import 语句确定的。

清单 20包含一个 UDDI tModel,这个 UDDI tModel 是根据只包含绑定定义的 WSDL 服务接口定义创建的。

清单 20:个案研究 4 UDDI tModel
<?xml version="1.0"?>
<tModel tModelKey="">
  <name>http://www.getquote.com/StockQuoteService-binding</name>

  <description xml:lang="en">
    Service interface binding definition for a stock quote service.
  </description>

  <overviewDoc>
    <description xml:lang="en">
      WSDL Service Interface Document
    </description>
    <overviewURL>
     http://www.getquote.com/services/SQS-binding.wsdl
    </overviewURL>
  </overviewDoc>

  <categoryBag>
    <keyedReference tModelKey="UUID:C1ACF26D-9672-4404-9D70-39B756E62AB4"
                    keyName="uddi-org:types" keyValue="wsdlSpec"/>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</tModel>

       

WSDL 服务实现定义
WSDL 服务实现文档包含一个 import 引用,它只引用包含绑定定义的 WSDL 服务接口文档。对这个服务定义进行操作的 WSDL 工具或运行时环境必须能够遵循完整的导入链。这个文档将导入包含 binding 元素的 WSDL 文档,然后它导入包含 types、message 和 portType 元素的 WSDL 文档。这 3 个文档全部结合在一起提供一个完整的 WSDL 服务定义。

清单 21:个案研究 5 WSDL 服务实现定义
<?xml version="1.0"?>
<definitions name="StockQuoteService"
  targetNamespace="http://www.getquote.com/StockQuoteService"
  xmlns:binding="http://www.getquote.com/StockQuoteService-binding"   
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns="http://schemas.xmlsoap.org/wsdl/">

  <import namespace="http://www.getquote.com/StockQuoteService-binding"
     location="http://www.getquote.com/wsdl/SQS-binding.wsdl"/>

  <service name="StockQuoteService">
    <documentation>Stock Quote Service</documentation>
    
    <port name="SingleSymbolService"
        binding="binding:SingleSymbolBinding">
      <soap:address location="http://www.getquote.com/stockquoteservice"/>
    </port>
  </service>
</definitions>
       

发布 UDDI businessService
WSDL 服务实现定义是作为 UDDI businessService 被发布的。每个 tModel 都将被使用 tModelInstanceInfo 元素引用。两个 tModel 都是引用,因此可使用任一个 tModel 执行搜索操作。

必须遍历导入链来确定需要的 tModelInstanceInfo 的数目。对于这个个案研究,导入链中只有两个服务接口文档,所以将只在 bindingTemplate 中指定两个 tModelInstanceInfo 元素。

第 1 个 tModelInstanceInfo 将包含对包含绑定定义的服务接口文档的引用。这个 tModelInstanceInfo 还将包含一个将引用 WSDL 服务实现文档的 overviewURL。

第 2 个 tModelInstanceInfo 元素将引用与包含 message 和 portType 元素的服务接口相关联的 tModel。这个 tModelInstanceInfo 将不包含 overviewURL 元素。

清单 22:个案研究 5 UDDI businessService
<?xml version="1.0"?>
<businessService businessKey="" serviceKey="">
  <name>StockQuoteService</name>

  <description xml:lang="en">
    Stock Quote Service
  </description>

  <bindingTemplates>
    <bindingTemplate bindingKey="" serviceKey="">
      <accesssPoint URLType="http">
        http://www.getquote.com/stockquoteservice
      </accessPoint>
      <tModelInstanceDetails>
        <tModelInstanceInfo 
            tModelKey="[tModel Key for binding Service Interface]">
          <instanceDetails>
            <overviewURL>
              http://www.getquote.com/services/SQS.wsdl#SingleSymbolService
            </overviewURL>
          </instanceDetails>
        </tModelInstanceInfo>
      </tModelInstanceDetails>
    </bindingTemplate>
  </bindingTemplates>
    
  <categoryBag>
    <keyedReference tModelKey="UUID:DB77450D-9FA8-45D4-A7BC-04411D14E384" 
                    keyName="Stock market trading services" 
                    keyValue="84121801"/>
  </categoryBag>
</businessService>
       

总结
在本文中,我讨论了几个 WSDL 用法个案研究,它们展示了如何在 UDDI 注册中心发布不同类型的 WSDL 服务描述。这些个案研究提供了基于 XML 的从 WSDL 到适当的 UDDI 数据实体的映射。这个系列的下一篇文章将展示如何使用 UDDI for Java API(UDDI4J)和“Java 工具箱 Web 服务描述语言”(Web Services Description Language for Java Toolkit(WSDL4J))通过编程在 UDDI 注册中心发布 WSDL 服务描述。这两个包都是开放源代码的项目,可在 参考资料部分访问。

参考资料

关于作者
Peter Brittenham 目前是 IBM Web Services Toolkit的首席体系架构设计师。Web 服务工具箱(Web Services Toolkit)包含使用 SOAP 和 WSDL 构建 Web 服务所需的工具和运行时支持,以及在 UDDI 注册中心发布和查找服务定义的运行时支持。可通过 peterbr@us.ibm.com与他联系。

posted on 2005-06-21 13:28 笨笨 阅读(646) 评论(0)  编辑  收藏 所属分类: J2EEALL

只有注册用户登录后才能发表评论。


网站导航: