享受代码,享受人生

SOA is an integration solution. SOA is message oriented first.
The Key character of SOA is loosely coupled. SOA is enriched
by creating composite apps.
posts - 207, comments - 2345, trackbacks - 162, articles - 44
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

webservice Quiz(Wsdl &Soap)

Posted on 2006-01-14 12:29 idior 阅读(4409) 评论(13)  编辑 收藏 网摘 所属分类: Web Services & SOA.Net

 

  <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>


原理说明

Feedback

#1楼[楼主]   回复  引用  查看    

2006-01-14 13:20 by idior      
如果你在哪里看到过对此问题的解释,望告知链接或书名

#2楼   回复  引用  查看    

2006-01-14 16:10 by hbifts      
???是直接显示为???吗?
还是编码的问题显示不了呢?

#3楼[楼主]   回复  引用  查看    

2006-01-14 16:38 by idior      
晕 看来我表达出了问题.
我是问???应该是什么,是Addoperation 还是 Add?

#4楼   回复  引用  查看    

2006-01-15 11:20 by 双鱼座      
楼主要自己写SoapHttpClientProtocol吗?

#5楼[楼主]   回复  引用  查看    

2006-01-15 13:38 by idior      
看来还真没有人注意这个问题。 玩webservice总不能就停留在添加web引用上吧?
可以说这个问题就很好的反映了web service基于消息交换的本质

◎双鱼座
我准备在Ws-Coordinate上做些文章

#6楼   回复  引用  查看    

2006-01-16 11:05 by 双鱼座      
汗!太高深莫测!从Delphi时代就玩过Web Services居然也不知道Ws-Coordinate是何物。我甚至完全不关心Soap协议,从实用的角度看相关的类库已经封装得非常好了。
不是说必须玩你这一套才不算停留在添加Web引用阶段吧?

#7楼[楼主]   回复  引用  查看    

2006-01-16 14:21 by idior      
Ws-Coordinate主要用于支持事务。也是实现service之间的组合基础。
其实上面这个问题, 不仅仅是soap细节的问题, 上面的答案是Add(消息元素名)而不是Addoperation(方法名), 这样你可以很容易的看出来Web service具有基于文档交换的消息处理模式, 而不是简单的远程方法调用(比如我可以发一个Add消息给服务器,然后服务器就会给予回应,而不是非要调用addoperation方法才行), 这可是Web service的核心概念之一。

#8楼   回复  引用  查看    

2006-01-17 13:39 by hbifts      
ms我以前看过的文章(还是书来着的),提到,WS不是远程调用,只是数据的发送和接收.

#9楼[楼主]   回复  引用  查看    

2006-01-17 13:54 by idior      
web service可以当作rpc,但是应该更多的被当作异步消息传递来使用

#10楼   回复  引用    

2006-02-17 10:01 by zhuang[未注册用户]
当然是AddOperation了,因为它表示的是调用的方法名称;

#11楼[楼主]   回复  引用  查看    

2006-02-19 12:13 by idior      
@zhuang
答案是Add,至少在asmx中是这样的

#12楼   回复  引用    

2006-06-01 10:31 by some one name dennis[未注册用户]
其实重要的是这一行
<soap:operation soapAction="http://idior.cnblogs.com/Math/Add" style="document" />

无论你写AddOperation还是Add,只要以上那一行是对的,那么都应该可以跑。

远程调用和Web Service其实是两回事。但是功用相近,所以很容易混淆。
Web Service 是一种服务,举个例就是你要知道某个问题的答案,你就去问Web Service,Web Service就会回复你。

远程调用呢,则是你要知道某个问题的答案,你就需要建立一个proxy object (对不起,不知道中文的词)。然后proxy object就会替你在远程的主机创造真正的object. 当你呼叫proxy object 的 function时,它也会替你叫主机哪儿的object去运行相关的function,然后再拿答案回来给你。

#13楼   回复  引用    

2008-01-11 11:22 by lauxp[未注册用户]
document literal wrap



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 317180 wRAAG7NGArs=



相关文章:

相关链接: