webservice中WSDL文档的解析

来源:互联网 发布:新网域名转入万网 编辑:程序博客网 时间:2024/05/21 07:01

1.WSDL 文档仅仅是一个简单的 XML 文档。它包含一系列描述某个 web service 的定义      

2.一个WSDL文档通常包含7个重要的元素,即types、import、message、portType、operation、binding、 service元素。这些元素嵌套在definitions元素中,definitions是WSDL文档的根元素。

WSDL 文档在Web服务的定义中使用下列元素:(并没有看懂)

  • Types - 数据类型定义的容器,它使用某种类型系统(一般地使用XML Schema中的类型系统)。
  • Message - 通信消息的数据结构的抽象类型化定义。使用Types所定义的类型来定义整个消息的数据结构
  • Operation - 对服务中所支持的操作的抽象描述,一般单个Operation描述了一个访问入口的请求/响应消息对。
  • PortType - 对于某个访问入口点类型所支持的操作的抽象集合,这些操作可以由一个或多个服务访问点来支持。
  • Binding - 特定端口类型的具体协议和数据格式规范的绑定。
  • Port - 定义为协议/数据格式绑定与具体Web访问地址组合的单个服务访问点。
  • Service- 相关服务访问点的集合。


    

一个简单的Web Service的WSDL文档,该服务支持名为sayHello的唯一操作,该操作通过在http上运行SOAP协议来实现的。该请求接受一个字符串name,经过处理后返回一个简单的字符串。文档如下:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
    
targetNamespace="http://com.liuxiang.xfireDemo/HelloService"
    xmlns:tns
="http://com.liuxiang.xfireDemo/HelloService"
    xmlns:wsdlsoap
="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soap12
="http://www.w3.org/2003/05/soap-envelope"
    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/">
<!--types中 name描述的是方法的名称(sayhello),sequence中的是参数(name1:String类型,name2:String类型),type中定义的是参数类型,响应信息(sayhelloResponse)--!>
    
<wsdl:types>
        
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            attributeFormDefault
="qualified" elementFormDefault="qualified"
            targetNamespace
="http://com.liuxiang.xfireDemo/HelloService">
<!--定义的方法,将来用来描述操作的参入传入部分--!>
            
<xsd:element name="sayHello">
                
<xsd:complexType>
                    
<xsd:sequence>
                        
<xsd:element maxOccurs="1" minOccurs="1"
                            name
="name1" nillable="true" type="xsd:string" />
                       <xsd:element maxOccurs="1" minOccurs="1"
                            name
="name2" nillable="true" type="xsd:string" />
                    
</xsd:sequence>
                
</xsd:complexType>
            
</xsd:element>
<!--响应信息,将来用来描述操作的返回值--!>
            
<xsd:element name="sayHelloResponse">
                
<xsd:complexType>
                    
<xsd:sequence>
                        
<xsd:element maxOccurs="1" minOccurs="1"
                            name
="out" nillable="true" type="xsd:string" />
                    
</xsd:sequence>
                
</xsd:complexType>
            
</xsd:element>
        
</xsd:schema>
    
</wsdl:types>
<!--message元素指定XML 数据类型组成消息的各个部分。message元素用于定义操作的输入和输出参数--!>
如果采用RPC样式的消息传递,只需要将文档中的element元素应以修改为type即可。
<!--sayHelloRequest:sayHello操作的请求消息格式,由一个消息片断组成,名字为parameters--!>

    
<wsdl:message name="sayHelloResponse">
        
<wsdl:part name="parameters" element="tns:sayHelloResponse" />
    
</wsdl:message>
<!--sayHelloRequest:sayHello操作的响应消息格式,由一个消息片断组成,名字为parameters--!>
    
<wsdl:message name="sayHelloRequest">
        
<wsdl:part name="parameters" element="tns:sayHello" />
    
</wsdl:message>
<!--portType元素和operation元素描述了Web服务的接口并定义了他的方法。portType元素和operation元素类似于 java接口和接口中定义的方法声明--!>
portType元素中定义了Web服务的操作。操作定义了输入和输出数据流中可以出现的XML消息。
 * 一些抽象操作的集合。每个操作关联一个输入消息和一个输出消息

    <wsdl:portType name="HelloServicePortType">
        
<wsdl:operation name="sayHello">
<!--portType定义了服务的调用模式的类型,这里包含一个操作sayHello方法,同时包含input和output表明
 * 该操作是一个 请求/响应模式,请求消息是前面定义的sayHelloRequest,
 * 响应消息是前面定义的 sayHelloResponse。input表示传递到Web服务的有效负载,  *output消息表示传递给客户的有效负载。--!>

            <wsdl:input name="sayHelloRequest"
                message
="tns:sayHelloRequest" />
            
<wsdl:output name="sayHelloResponse"
                message
="tns:sayHelloResponse" />
        
</wsdl:operation>
    
</wsdl:portType>
<!--binding 元素描述特定服务接口的协议、数据格式、安全性和其它属性。   * 针对操作和portType中使用的消息指定实际的协议和数据格式规范--!>
    <wsdl:binding name="HelloServiceHttpBinding"
        type
="tns:HelloServicePortType">
        
<wsdlsoap:binding style="document"
            transport
="http://schemas.xmlsoap.org/soap/http" />
        
<wsdl:operation name="sayHello">
            
<wsdlsoap:operation soapAction="" />
            
<wsdl:input name="sayHelloRequest">
                
<wsdlsoap:body use="literal" />
            
</wsdl:input>
            
<wsdl:output name="sayHelloResponse">
                
<wsdlsoap:body use="literal" />
            
</wsdl:output>
        
</wsdl:operation>
    
</wsdl:binding>
<!--service元素。服务元素包含一组port元素。端口将端点与来自服务接口定义的binding 元素关联起来。  port指定一个绑定的地址,这样定义一个通信的终端。--!>
    
<wsdl:service name="HelloService">
        
<wsdl:port name="HelloServiceHttpPort"
            binding
="tns:HelloServiceHttpBinding">
            
<wsdlsoap:address
                
location="http://localhost:8080/xfire/services/HelloService" />
        
</wsdl:port>
    
</wsdl:service>

</wsdl:definitions>


0 0