• webservice Quiz(Wsdl &Soap)


      <wsdl:types />
      
    <wsdl:message name="AddSoapIn">
        
    <wsdl:part name="a" type="s:int" />
        
    <wsdl:part name="b" type="s:int" />
      
    </wsdl:message>
      
    <wsdl:message name="AddSoapOut">
        
    <wsdl:part name="AddResult" type="s:int" />
      
    </wsdl:message>
      
    <wsdl:portType name="MathServiceSoap">
        
    <wsdl:operation name="Add">
          
    <wsdl:input message="tns:AddSoapIn" />
          
    <wsdl:output message="tns:AddSoapOut" />
        
    </wsdl:operation>
      
    </wsdl:portType>
      
    <wsdl:binding name="MathServiceSoap" type="tns:MathServiceSoap">
        
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
        
    <wsdl:operation name="Add">
          
    <soap:operation soapAction="http://idior.cnblogs.com/Math/Add" style="rpc" />
          
    <wsdl:input>
            
    <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
          
    </wsdl:input>
          
    <wsdl:output>
            
    <soap:body use="encoded" namespace="http://tempuri.org/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
          
    </wsdl:output>
        
    </wsdl:operation>
      
    </wsdl:binding>


    以上是一段wsdl的片断,其中主要定义了一个Add方法。针对粗体字部分,我们得到以下使用该webservice的soap请求。

    POST /WebService1/Service1.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://idior.cnblogs.com/Math/Add"

    <?xml version="1.0" encoding="utf-8"?>
    <
    soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:types="http://tempuri.org/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <
    soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <
    tns:Add>
          <
    xsi:type="xsd:int">int</
    a>
          <
    xsi:type="xsd:int">int</
    b>
        </
    tns:Add>
      </
    soap:Body>
    </
    soap:Envelope>


    可以看出在WSDL中定义好的SoapAction被放在了Http的请求头中, 为了调用Add这个WebService中的方法,SOAP包中粗体字部分发出的请求恰恰对应了WSDL中定义的operation的name---Add.

    那么对于下面的WSDL文件,我们又该发出怎样的SOAP请求呢?

    <wsdl:types>
        
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
          
    <s:element name="Add">
            
    <s:complexType>
              
    <s:sequence>
                
    <s:element minOccurs="1" maxOccurs="1" name="a" type="s:int" />
                
    <s:element minOccurs="1" maxOccurs="1" name="b" type="s:int" />
              
    </s:sequence>
            
    </s:complexType>
          
    </s:element>
          
    <s:element name="AddReponse">
            
    <s:complexType>
              
    <s:sequence>
                
    <s:element minOccurs="1" maxOccurs="1" name="AddOperationResult" type="s:int" />
              
    </s:sequence>
            
    </s:complexType>
          
    </s:element>
        
    </s:schema>
      
    </wsdl:types>
      
    <wsdl:message name="AddOperationSoapIn">
        
    <wsdl:part name="parameters" element="tns:Add" />
      
    </wsdl:message>
      
    <wsdl:message name="AddOperationSoapOut">
        
    <wsdl:part name="parameters" element="tns:AddReponse" />
      
    </wsdl:message>
      
    <wsdl:portType name="MathServiceSoap">
        
    <wsdl:operation name="AddOperation">
          
    <wsdl:input message="tns:AddOperationSoapIn" />
          
    <wsdl:output message="tns:AddOperationSoapOut" />
        
    </wsdl:operation>
      
    </wsdl:portType>
      
    <wsdl:binding name="MathServiceSoap" type="tns:MathServiceSoap">
        
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
        
    <wsdl:operation name="AddOperation">
          
    <soap:operation soapAction="http://idior.cnblogs.com/Math/Add" style="document" />
          
    <wsdl:input>
            
    <soap:body use="literal" />
          
    </wsdl:input>
          
    <wsdl:output>
            
    <soap:body use="literal" />
          
    </wsdl:output>
        
    </wsdl:operation>
      
    </wsdl:binding>


    现在为了调用AddOperation(注意 Add改成AddOperation了)方法,你认为Soap Body中对应的那个元素名???是什么呢?

    POST /WebService1/Service1.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://idior.cnblogs.com/Math/Add"

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      
    <soap:Body>
        
    <??? xmlns="http://tempuri.org/">
          <a>int</a>
          <b>int</b>
        </???

      
    </soap:Body>
    </soap:Envelope>


    原理说明
  • 相关阅读:
    Hadoop面试
    Node.js面试题
    Node.js面试题
    [转载]最好的关系,是我懂你的不容易
    据说练就了一指禅神功的觅闻实时手机新闻网,正以每天2000+IP的用户量递增。有智能手机的可以当场进行体验,没有的就算了哈
    刚6瓶啤酒4两56度白酒下肚,居然20分钟做了一手机版网站 !
    Android:刚6瓶啤酒4两56度白酒下肚,居然20分钟做了一手机版网站 !
    IT人生的价值和意义 感觉真的有了
    (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议 (图)
    (Android 即时通讯) [悬赏],无论是谁发现一个漏洞奖励人民币1000元!
  • 原文地址:https://www.cnblogs.com/idior/p/317180.html
Copyright © 2020-2023  润新知