zoukankan      html  css  js  c++  java
  • 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>

    http://www.cnblogs.com/ryhan/archive/2011/05/03/2035633.html
  • 相关阅读:
    jquery扩展鼠标mousewheel事件
    addEventListener和attachEvent介绍, 原生js和jquery的兼容性写法
    HTML,CSS,font-family:中文字体的英文名称
    最好的Java和Android开发IDE---IntelliJ IDEA使用技巧
    《Thinking in Java》习题——吸血鬼数字
    Java学习之——JavaBeans
    Android 开源库——侧滑菜单栏(SlidingMenu)的导入和使用
    Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)
    Android 布局学习之——Layout(布局)详解一
    Android 布局学习之——LinearLayout的layout_weight属性
  • 原文地址:https://www.cnblogs.com/ryhan/p/2035634.html
Copyright © 2011-2022 走看看