乐在其中

以JEE为主攻,以Flex为点缀,以Eclipse RCP为乐趣
请访问http://www.inframesh.org

首页 新随笔 联系 管理
  43 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

最近写Web service, 很多代码是用工具生成的,可以说只知其然,不知其所以然。于是,去网上搜了写wsdl的规范看了看,初步理了理头绪,总结一下。

1. wsdl文件格式的结构比较固定,总共分那么几块:definitions/type/message/portType/binding/service,每一块handle不同的职责

2. 一般建议定义单独的xml schema, 然后在不同的wsdl中复用

3. 绑定部分很灵活,你可以选择不同的协议绑定,我们主要绑定到soap

4. server-side和client-side部分的代码生成可以借助不同的工具,我使用的axis2. 不过生成的代码比较难看。axis2是个SOAP engin

具体wsdl详解可以参考天极网的一个专题:http://www.yesky.com/zhuanti/259/200759.shtml

下面是就我写的一个wsdl文件做得注解:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions 
    targetNamespace="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateral/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:tns="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateral/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    name="splitRawCollateral">
<!--  
xmlns:soap, xmlns:tns, xmlns:wsdl, xmlns:xsd分别定义了命名空间缩写,后面就可以如下使用:soap:int ..
xmlns:tns 一般指当前namespace的缩写(ThisNameSpace),即与targetNamespace相同
-->
 
  <!-- ===================================== 抽象定义 ===============================================   -->
  
  <!-- +++++++++++++++ Types(独立于机器和语言的类型定义) ++++++++++++++++++++ -->
  <wsdl:types>
    <xsd:schema targetNamespace="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateral/" 
                xmlns:Q1="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateral/schema">
      <!-- ++++引入已定义的schema文件++++++ -->
      <xsd:import schemaLocation="splitRawCollateral.xsd" namespace="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateral/schema">
      </xsd:import>
      <xsd:element name="queryRawCollateralByCustomer">
        <xsd:complexType>
          <xsd:sequence>
 
              <xsd:element ref="Q1:customerBO" minOccurs="0" maxOccurs="1"></xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="queryRawCollateralByCustomerResponse">
        <xsd:complexType>
          <xsd:sequence>
 
              <xsd:element ref="Q1:customerBO" minOccurs="0" maxOccurs="unbounded"></xsd:element>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="savaSplittedCollateral">
          <xsd:complexType>
              <xsd:sequence>
 
                  <xsd:element ref="Q1:rawCollateralBO"></xsd:element>
              </xsd:sequence>
          </xsd:complexType>
      </xsd:element>
      <xsd:element name="savaSplittedCollateralResponse">
          <xsd:complexType>
              <xsd:sequence>
 
                  <xsd:element name="result" type="xsd:string"></xsd:element>
              </xsd:sequence>
          </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  
  <!-- +++++++++++++++ Message(包括函数参数(输入与输出分开)或文档描述) ++++++++++++++++++++ -->
  <wsdl:message name="queryRawCollateralByCustomerRequest">
    <wsdl:part name="queryRawCollateralByCustomerRequest" element="tns:queryRawCollateralByCustomer" />
  </wsdl:message>
  <wsdl:message name="queryRawCollateralByCustomerResponse">
    <wsdl:part name="queryRawCollateralByCustomerResponse" element="tns:queryRawCollateralByCustomerResponse" />
  </wsdl:message>
  <wsdl:message name="savaSplittedCollateralRequest">
      <wsdl:part name="savaSplittedCollateralRequest" element="tns:savaSplittedCollateral" />
  </wsdl:message>
  <wsdl:message name="savaSplittedCollateralResponse">
      <wsdl:part name="savaSplittedCollateralResponse" element="tns:savaSplittedCollateralResponse" />
  </wsdl:message>
  
  <!-- +++++++++++++++ PortType(引用消息部分中消息定义来描述函数签名(操作名、输入参数、输出参数)) ++++++++++++++++++++ -->
  <wsdl:portType name="splitRawCollateral">
    <wsdl:operation name="queryRawCollateralByCustomer">
      <wsdl:input message="tns:queryRawCollateralByCustomerRequest"/>
      <wsdl:output message="tns:queryRawCollateralByCustomerResponse"/>
    </wsdl:operation>
    <wsdl:operation name="savaSplittedCollateral">
        <wsdl:input message="tns:savaSplittedCollateralRequest" />
        <wsdl:output message="tns:savaSplittedCollateralResponse" />
    </wsdl:operation>
  </wsdl:portType>
  
  <!-- ===================================== 具体定义 ===============================================   -->
  
  <!-- +++++++++++++++ Binding(PortTypes部分的每一操作在此绑定实现) ++++++++++++++++++++ -->
  <wsdl:binding name="splitRawCollateralSOAP" type="tns:splitRawCollateral">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="queryRawCollateralByCustomer">
      <soap:operation soapAction="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateralService/queryRawCollateralByCustomer"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    
    <wsdl:operation name="savaSplittedCollateral">
      <soap:operation soapAction="http://services.icms.********.com/abstraction/atomic/icms/splitRawCollateralService/savaSplittedCollateral"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  
  <!-- +++++++++++++++ Service(确定每一绑定的端口地址) ++++++++++++++++++++ -->
  <wsdl:service name="splitRawCollateral">
    <wsdl:port binding="tns:splitRawCollateralSOAP" name="splitRawCollateralSOAP">
      <soap:address location="http://www.example.org/"/>
    </wsdl:port>
  </wsdl:service>
  
</wsdl:definitions>
posted on 2008-12-15 11:27 suprasoft Inc,. 阅读(3784) 评论(0)  编辑  收藏

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


网站导航:
 
©2005-2008 Suprasoft Inc., All right reserved.