wsdl中的wsdl soapaction为空属性,有什么用

君,已阅读到文档的结尾了呢~~
wsdl生成客户端、wsdl接口测试及简介(有网络和无网络),wsdl生成客户端,wsdl生成客户端代码,wsdl生成java客户端,wsdl 客户端,wsdl文件生成,php 生成wsdl,wsdl生成代理类,wsdl文件怎么生成,webservice生成wsdl
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
wsdl生成客户端、wsdl接口测试及简介(有网络和无网络)
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口我的图书馆
<binding>和<operation>元素  Binding栏是完整描述协议、序列化和编码的地方,Types, Messages和PortType栏处理抽象的数据内容,而Binding栏是处理数据传输的物理实现。Binding栏把前三部分的抽象定义具体化。  把相关的数据制定和消息声明分开,这意味着同一类型服务的提供者可以把一系列的操作标准化。每个提供者可以提供定制的binding来互相区分。WSDL也有一个重要的结构,使抽象定义可以放在分离的文件中,而不是和Bindings和Services在一起,这样可在不同的服务提供者之间提供标准化的抽象定义,这很有帮助。例如,银行可以用WSDL文档来标准化一些银行的操作。每个银行仍然可以自由的订制下层的协议、串行优化,及编码。  下面是重载的WSDL示例 的Binding栏,重复在此以便讨论:
<binding name="fooSampleBinding" type="wsdlns:fooSamplePortType"><stk:binding preferredEncoding="UTF-8" /><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="foo"> <soap:operation soapAction="http://tempuri.org/action/foo1"/>  <input name="foo1">   <soap:body use="encoded" namespace="http://tempuri.org/message/"         encodingStyle=         "http://schemas.xmlsoap.org/soap/encoding/" />  </input> </operation><operation name="foo"><soap:operation soapAction="http://tempuri.org/action/foo2"/> <input name="foo2">  <soap:body use="encoded"          namespace="http://tempuri.org/message/"        encodingStyle=          "http://schemas.xmlsoap.org/soap/encoding/" /> </input></operation></binding>
  <binding>元素已经取了一个名字(本例中"fooSampleBinding"),这样就可以被Services栏的<port>元素引用了。它有一个"type"的属性引用<portType>,本例中就是"wsdlns:fooSamplePortType"。第二行是MSTK2的扩展元素<stk:binding>,它指定了preferredEncoding属性为"UTF-8"。  <soap:binding>元素指定了所使用的风格("rpc")和传输方式。Transport属性应用了一个namespace,正是这个namespace指明使用HTTP SOAP协议。  有两个同以"foo"命名的<operation>元素。唯一不同的是它们各自的<input>名字,分别为"foo1"和"foo2"。两个<operation>元素中的<soap:operation>元素有同样的"soapAction"属性,是URI。soapAction属性是SOAP特定的URI,它只是简单的使用于SOAP消息。所产生的SOAP消息有一个SOAPAction头,而URI也仅在<soap:operation>元素里才起作用。soapAction属性在HTTP的binding中是必需的,但在其他非HTTP binding中却不要提供。目前它的使用并不清楚,但它似乎有助于本例中的两个"foo"操作。SOAP 1.1指明soapAction用来确定消息的"意图"。似乎服务器可以在不解析整个消息的情况下就能使用这一属性来发送消息。实际上,它的使用多种多样。<soap:operation>元素也可以包含另一属性,即"style"属性,在有必要冲突<soap:binding>元素指定的风格时可以使用。  <operation>属性可以包含<input>, <output> 和<fault>的元素,它们都对应于PortType栏中的相同元素。只有<input>元素在上例中提供。这三个元素中的每一个可有一个可选的"name"属性,在本例中,我们用这种方法来区分同名操作。在本例的<input>元素中有一个<soap:body>元素,它指定了哪些信息被写进SOAP消息的信息体中。该元素有以下属性:  Use   用于制定数据是"encoded"还是"literal"。"Literal"指结果SOAP消息包含以抽象定义(Types, Messages, 和PortTypes)指定格式存在的数据。"Encoded"指"encodingStyle"属性决定了编码方式。  Namespace   每个SOAP消息体可以有其自己的namespace来防止命名冲突。这一属性制定的URI在结果SOAP消息中逐字使用。  EncodingStyle   对SOAP编码,它应该有以下URI值:
"http://schemas.xmlsoap.org/soap/encoding"
文档风格实现  在前几栏中,<soap:binding>元素有一个类型属性,设为"rpc"。此属性设为"document"时会改变传输时消息的串行化。不同于函数签名,现在的消息是文档传输的。在这类binding中,<message>元素定义文档格式,而不是函数签名。作为例子,考虑以下WSDL片段:
<definitionsxmlns:stns="(SchemaTNS)"xmlns:wtns="(WsdlTNS)"targetNamespace="(WsdlTNS)"><schema targetNamespace="(SchemaTNS)"elementFormDefault="qualified"><element name="SimpleElement" type="xsd:int"/><element name="CompositElement" type="stns:CompositeType"/><complexType name="CompositeType"><all> <element name='a' type="xsd:int"/> <element name='b' type="xsd:string"/></all></complexType></schema><message...> <part name='p1' type="stns:CompositeType"/> <part name='p2' type="xsd:int"/> <part name='p3' element="stns:SimpleElement"/> <part name='p4' element="stns:CompositeElement"/></message>…</definitions>
  schema有两个元素:SimpleElement和CompositeElement,还有一个类型声明(CompositeType)。唯一声明的<message>元素有四个部分:p1:Composite型;p2:int型;p3:SimpleElement型;p4:CompositeElement型。以下有一个表,对四种类型的use/type决定的binding作一比较:rpc/literal, document/literal, rpc/encoded, 以及document/encoded。表指明了每种binding的表现。  <service>和<port>元素  service是一套<port>元素。在一一对应形式下,每个<port>元素都和一个location关联。如果同一个<binding>有多个<port>元素与之关联,可以使用额外的URL地址作为替换。一个WSDL文档中可以有多个<service>元素,而且多个<service>元素十分有用,其中之一就是可以根据目标URL来组织端口。这样,我就可以方便的使用另一个<service>来重定向我的股市查询申请。我的客户端程序仍然工作,因为这种根据协议归类的服务不随服务而变化。多个<service>元素的另一个作用是根据特定的协议划分端口。例如,我可以把所有的HTTP端口放在同一个<service>中,所有的SMTP端口放在另一个<service>里。我的客户可以搜索与它可以处理的协议相匹配的<service>。
<service name="FOOService"><port name="fooSamplePort" binding="fooSampleBinding"> <soap:address   location="http://carlos:8080/fooService/foo.asp"/></port></service>
  在一个WSDL文档中,<service>的name属性用来区分不同的service。因为同一个service中可以有多个端口,它们也有"name"属性。  总结  本文中我描述了WSDL文档关于SOAP方面的最显著的特点。不过应该说明的是WSDL并不仅限于HTTP上的SOAP。WSDL用来描述HTTP-POST、HTTP-GET、SMTP及其他协议时非常清晰。使用了WSDL,SOAP更加容易处理了,无论是开发者还是使用者。我相信WSDL和SOAP一起将会开创网络应用程序世界的新时代。  WSDL的namespace里有一系列的XML元素。下表概述了那些元素、它们的属性和内容。
内容(子元素)
<definitions>
nametargetNamespacexmlns (other namespaces)
<types><message><portType><binding><service>
<xsd:schema>
<message>
<portType>
<operation>
<binding>
<operation>
<service>
<operation>
nameparameterOrder
<input><output><fault>
namemessage
<output>
namemessage
namemessage
namebinding
<soap:address>
      资源:  1.   2.   3.   4.   5.   6.   7.
发表评论:
TA的最新馆藏[转]&Axis WSDL文件中关于SoapAction值的疑问 - ITeye问答
在Axis2提供的sample中: axis2-1.6.0\samples\mtom\resources\MTOMSample.wsdl
对这个wsdl文件中的WS-Addressing有关的Action属性不是很理解。
portType中的input/output的Action属性和binding中的soapAction有什么关系吗?
他们是属性值是怎么来的?有什么作用?
&wsdl:definitions xmlns:tns="http://ws.apache.org/axis2/mtomsample/"
....
&wsdl:portType name="MTOMServicePortType"&
&wsdl:operation name="attachment"&
&wsdl:input message="tns:AttachmentRequest"
wsaw:Action="attachment" /&
&wsdl:output message="tns:AttachmentResponse"
wsaw:Action="http://schemas.xmlsoap.org/wsdl/MTOMServicePortType/AttachmentResponse" /&
&/wsdl:operation&
&/wsdl:portType&
&wsdl:binding name="MTOMServiceSOAP11Binding"
type="tns:MTOMServicePortType"&
&wsdl:operation name="attachment"&
&soap:operation soapAction="attachment" style="document" /&
&/wsdl:operation&
&/wsdl:binding&
&/wsdl:definitions&
目前还没有答案
已解决问题
未解决问题手工创建的SOAP消息中命名空间的处理
手工创建的SOAP消息中命名空间的处理
  引言    在典型的 Web 服务场景中,通常使用工具技术来处理命名空间的所有细微差别。但是有些时候,特别是在使用 SAAJ(SOAP with Attachments API for Java)为特定的 Web 服务构造 SOAP 消息时,您必须自己处理命名空间问题。在没有任何工具辅助的情况下构造消息DD或是部分消息时DD可以使用该技巧。    虽然命名空间看似复杂,但您真正只需要掌握的是以下一份简短的规则清单:    如果 WSDL 样式为 RPC,那么可在 WSDL 绑定的 wsdlsoap:body 元素中查看命名空间。    如果 wsdlsoap:body 有命名空间属性(且 Web 服务互操作性组织(WS-I)的 Basic Profile(参见参考资料部分)需要该属性用于 RPC 样式),那么这就是 SOAP 消息中操作元素的命名空间。    如果 wsdlsoap:body 没有命名空间,那么该操作元素不符合要求。    对于数据元素而言:    如果元素通过根元素(不是根类型)定义,那么它的命名空间就是根元素的命名空间;    如果元素不是通过根定义的,那么该元素不符合要求(对于该规则的说明请参见以下 elementFormDefault 部分的讨论。)    这些都是简单的规则,但如同大多数规则一样,需要对其进行少许说明。本文的其余部分将展示使用这些规则的各类实例。    有两种常用类型的 Web 服务描述语言(WSDL)文件: RPC/literal 和 document/literal 封装。当然还有其它的类型,但在本文中只包含这两种。(各类 WSDL 的详细内容参见文章“我应该使用哪种样式的 WSDL?”DD参见参考资料。)    RPC/literal WSDL    清单 1 中的 RPC/literal WSDL 有三个操作:op1、op2 和 op3。注意 WSDL 文件中用粗体强调的不同命名空间。    清单 1. RPC/literal WSDL  &?xml version="1.0" encoding="UTF-8"?>  &definitions  targetNamespace=""  xmlns=""  xmlns:tns=""  xmlns:data=""  xmlns:wsdlsoap="">  &types>  &schema  targetNamespace=""  xmlns=""  xmlns:tns="">  &element name="RefDataElem" type="int"/>  &/schema>  &schema  targetNamespace=""  xmlns=""  xmlns:ref=""  xmlns:tns=""  xmlns:xsd="">  &import namespace=""/>  &complexType name="Data">  &sequence>  &element name="data1" type="int"/>  &element name="data2" type="int"/>  &/sequence>  &/complexType>  &element name="DataElem" nillable=  "true" type="tns:Data"/>  &complexType name="Data2">  &sequence>  &element ref="ref:RefDataElem"/>  &/sequence>  &/complexType>  &/schema>  &/types>  &message name="op1Request">  &part name="in" type="data:Data"/>  &/message>  &message name="op1Response">  &part name="op1Return"  type="data:Data"/>  &/message>  &message name="op2Request">  &part name="in" type="data:Data"/>  &/message>  &message name="op2Response">  &part name="op2Return" type="data:Data"/>  &/message>  &message name="op3Request">  &part name="in1" element="data:DataElem"/>  &part name="in2" type="data:Data2"/>  &/message>  &message name="op3Response">  &part name="op3Return" type="data:Data2"/>  &/message>  &portType name="Sample">  &operation name="op1">  &input message="tns:op1Request"/>  &output message="tns:op1Response"/>  &/operation>  &operation name="op2">  &input message="tns:op2Request"/>  &output message="tns:op2Response"/>  &/operation>  &operation name="op3">  &input message="tns:op3Request"/>  &output message="tns:op3Response"/>  &/operation>  &/portType>  &binding name="SampleSoapBinding" type="tns:Sample">  &wsdlsoap:binding
transport=  ""/>  &operation name="op1">  &wsdlsoap:operation soapAction=""/>  &input>  &wsdlsoap:body namespace=  "" use="literal"/>  &/input>  &output>  &wsdlsoap:body namespace=  "" use="literal"/>  &/output>  &/operation>  &operation name="op2">  &wsdlsoap:operation soapAction=""/>  &input>  &wsdlsoap:body namespace=  "" use="literal"/>   &/input>  &output>  &wsdlsoap:body namespace=  "" use="literal"/>  &/output>  &/operation>  &operation name="op3">  &wsdlsoap:operation soapAction=""/>  &input>  &wsdlsoap:body use="literal"/>  &/input>  &output>  &wsdlsoap:body use="literal"/>  &/output>  &/operation>  &/binding>  &service name="SampleService">  &port binding="tns:SampleSoapBinding" name=  "Sample">  &wsdlsoap:address location=  //localhost:9080/RPCNamespaces/services/Sample"/>  &/port>  &/service>  &/definitions>    WS-I 遵从性    WS-I(参见参考资料)为 WSDL 定义遵从性标准。从两个方面来讲,op3 不遵从 RPC/literal WSDL:它并不在绑定的 wsdlsoap:body 中定义命名空间;它的消息部分引用了元素,而不是类型。在此提出是为了展示可以用 WS-I 的 Basic Profile 解决的一些命名空间问题。    查看用于每个操作的绑定的 wsdlsoap:body 元素中的命名空间。op1 和 op2 是规则 1.1 的实例(参见以下有关 SOAP 消息的内容)。op3 是规则 1.2 的实例。op1 展示了使用 targetNamespace 的常规实例DD在这种情况下是“”DD作为该操作的命名空间,但是这仅仅是通常情况。op2 使用的命名空间将不会在 WSDL 中的其他任何地方被使用。op3 无需定义任何命名空间。    清单 2、3 和 4 分别展示了 op1、op2 和 op3 的 SOAP 消息。注意消息中用粗体强调的命名空间。    清单 2. op1 的 RPC/literal 请求/响应 SOAP 消息    &soapenv:Envelope xmlns:soapenv=  "">  &soapenv:Body>  &p582:op1 xmlns:p582="">  &in>  &data1>1&/data1>  &data2>2&/data2>  &/in>  &/p582:op1>  &/soapenv:Body>  &/soapenv:Envelope>  &soapenv:Envelope xmlns:soapenv=  "">  &soapenv:Body>  &p582:op1Response xmlns:p582=  "">  &op1Return>  &data1>10&/data1>  &data2>20&/data2>  &/op1Return>  &/p582:op1Response>  &/soapenv:Body>  &/soapenv:Envelope>    在上文中已经提及,清单 2 中的 SOAP 消息遵从规则 1.1。op1 的命名空间为“”。这些消息同样遵从规则 2.2。所有参数数据都不通过根元素定义,仅仅是根类型DD数据DD以及它的子元素。既然没有使用根元素,那么这些元素都是不合要求的。    清单 3. op2 的 RPC/literal 请求/响应 SOAP 消息    &soapenv:Envelope xmlns:soapenv=  "">  &soapenv:Body>  &p999:op2 xmlns:p999=  "">  &in>  &data1>3&/data1>  &data2>4&/data2>  &/in>  &/p999:op2>  &/soapenv:Body>  &/soapenv:Envelope>  &soapenv:Envelope xmlns:soapenv=  "">  &soapenv:Body>  &p999:op2Response xmlns:p999=  "">  &op2Return>  &data1>300&/data
H3C认证Java认证Oracle认证
基础英语软考英语项目管理英语职场英语
.NETPowerBuilderWeb开发游戏开发Perl
二级模拟试题一级模拟试题一级考试经验四级考试资料
软件测试软件外包系统分析与建模敏捷开发
法律法规历年试题软考英语网络管理员系统架构设计师信息系统监理师
高级通信工程师考试大纲设备环境综合能力
路由技术网络存储无线网络网络设备
CPMP考试prince2认证项目范围管理项目配置管理项目管理案例项目经理项目干系人管理
职称考试题目
招生信息考研政治
网络安全安全设置工具使用手机安全
生物识别传感器物联网传输层物联网前沿技术物联网案例分析
Java核心技术J2ME教程
Linux系统管理Linux编程Linux安全AIX教程
Windows系统管理Windows教程Windows网络管理Windows故障
数据库开发Sybase数据库Informix数据库
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&下次自动登录
现在的位置:
& 综合 & 正文
SOAP和WSDL的一些必要知识
SOAP和WSDL对Web Service、WCF进行深入了解的基础,因此花一些时间去了解一下是很有必要的。
一、SOAP(Simple Object Access Protocol)
如果我们要调用远程对象的方法,就必定要告诉对方,我们要调用的是一个什么方法,以及这个方法的参数的值等等。然后对方把数据返回给我们。
这其中就涉及到两个问题:1、数据如何在网络上传输。2、如何表示数据?用什么格式去表示函数以及它的参数等等。
1、SOAP的传输协议
SOAP的传输协议使用的就是HTTP协议。只不过HTTP传输的内容是HTML文本,而SOAP协议传输的是SOAP的数据。看一下下面的例子:
这是一个HTTP请求(请求google的首页)的内容:
GET / HTTP/1.1 Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-us
User-Agent: Mozilla/4.0 ( MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.; .NET CLR 3.5.30729; CIBA) chromeframe/4.0
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Cookie: PREF=ID=d8f9f1710bfa5f72:U=a5b3bec86b6433ef:NW=1:TM=:LM=:GM=1:S=q2agYsw3BsoOQMAs; NID=29=JgIGDDUx70IQTBVAnNEP_E9PLLKBI9STjzaBjgq1eWuDg-_jCgFpka59DrOC0aZKLbj4q77HU1VMKscXTP3OaseyTbv643c2XPe9dS7lsXDHAkAnS46vy-OU8XRqbmxJ; rememberme= SID=DQAAAH4AAABW7M4nVkTeOR7eJUmC1AJ4R6hYbmVewuy_uItLUTzZMUTpojdaHUExhPa_EPAkO9Ex1u3r7aPXZ5cj28xHnv2DbfRYf5AyaBcimciuOTITKSIkqn3QSpGDFkRS1Xn7EGzDpCV0V1xFlCu0erf_jfe_D6GOgC2P2S08jNdFS9V HSID=AFEFTMA68EgN __utmx=.; __utmxx=.
---------如果有Post的数据,这里还会有Post的数据--------
这个是一个SOAP请求的内容:
POST /WebServices/WeatherWebService.asmx HTTP/1.1
User-Agent: Mozilla/4.0 ( MSIE 6.0; MS Web Services Client Protocol 2.0.)
Content-Type: text/ charset=utf-8SOAPAction: ".cn/getSupportCity"
Content-Length: 348
Expect: 100-continue
Connection: Keep-Alive
&?xml version="1.0" encoding="utf-8"?&&soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&&soap:Body&&getSupportCity xmlns=".cn/"&&byProvinceName&广东&/byProvinceName&&/getSupportCity&&/soap:Body&&/soap:Envelope&
可以看到,一个SOAP请求其实就是一个HTTP请求,但为了表明内容是SOAP的数据,需要加入上面请求中红色字的部分来以示区别。也就是说,如果请求头中有SOAPAction这一段,那么请求会被当作SOAP的内容来处理而不会当作HTML来解析。可以用上面指定SOAPAction头来表示内容是SOAP的内容,也可以指定
Content-Type: application/soap+xml 来表示内容是SOAP的内容。SOAP请求中最后的那段XML数据,这个就是请求的具体内容,这个就是SOAP规定的请求的数据格式,下面再详细对格式进行说明。
2、SOAP的数据格式
现在知道了SOAP是通过HTTP协议的POST方法来传输数据的,只不过是请求的Header中加了一些标志来说明自己是一个SOAP请求。那么数据的具体格式是怎么规定的呢,我们把上面请求的XML数据展开看一下:
&?xml version="1.0" encoding="utf-8"?&&soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&
&soap:Body&
&getSupportCity xmlns=".cn/"&
&byProvinceName&广东&/byProvinceName&
&/getSupportCity&
&/soap:Body&&/soap:Envelope&
其中的&soap:Body&里面的内容就是请求的内容,请求的方法为getSupportCity,该方法有一个名为byProvinceName的参数,参数的值为“广东”这个字符串。再看一下返回的内容:
HTTP/1.1 200 OK
Date: Mon, 14 Dec :39 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/ charset=utf-8
Content-Length: 1052
&?xml version="1.0" encoding="utf-8"?&&soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&&soap:Body&&getSupportCityResponse xmlns=".cn/"&&getSupportCityResult&&string&广州 (59287)&/string&&string&深圳 (59493)&/string&&string&潮州 (59312)&/string&&string&韶关 (59082)&/string&&string&湛江 (59658)&/string&&string&惠州 (59298)&/string&&string&清远 (59280)&/string&&string&东莞 (59289)&/string&&string&江门 (59473)&/string&&string&茂名 (59659)&/string&&string&肇庆 (59278)&/string&&string&汕尾 (59501)&/string&&string&河源 (59293)&/string&&string&揭阳 (59315)&/string&&string&梅州 (59117)&/string&&string&中山 (59485)&/string&&string&德庆 (59269)&/string&&string&阳江 (59663)&/string&&string&云浮 (59471)&/string&&string&珠海 (59488)&/string&&string&汕头 (59316)&/string&&string&佛山 (59279)&/string&&/getSupportCityResult&&/getSupportCityResponse&&/soap:Body&&/soap:Envelope&
返回的HTTP头中并没有标志来表明是一个SOAP的响应,因为的确没有必要,请求方发送出的SOAP请求,返回的肯定是SOAP的响应。
一个典型的SOAP请求格式的结构如下:
&?xml version="1.0"?&&soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"&
&soap:Header&
&m:Trans xmlns:m="/transaction/"
soap:mustUnderstand="1"&<span style="color:#4
&/m:Trans&&/soap:Header&
&soap:Body&
&m:GetPrice xmlns:m="/prices"&
&m:Item&Apples&/m:Item&
&/m:GetPrice&&/soap:Body&
&/soap:Envelope&
下面逐个解释里面的元素:
a) Envelope
SOAP的请求内容必须以Envelope做为根节点。
xmlns:soap="http://www.w3.org/2001/12/soap-envelope",不能修改,否则会出错。http://www.w3.org/2001/12/soap-envelope里面有Envelope的schema的相关定义。有兴趣的可以去这个链接的内容。
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding",这个指定了数据元素的类型。
这个是可选的,如果需要添加Header元素,那么它必须是Envelope的第一个元素。
Header的内容并没有严格的限制,我们可以自己添加一些和应用相关的内容,但是客户端一定要记得处理这些Header元素,可以加上mustUnderstand强制进行处理。
这个就是请求的主题内容了,请求什么函数,参数是什么类型等等都在这里面指定。
用标签表示一个函数,然后用子元素表示它的参数。
在调用中没有指定参数和返回类型,这里不需要指定,因为提供服务的一方自己已经规定好了数据类型,在调用时指定数据类型没有任何意义。
二、WSDL(Web Services Description Language)
  WSDL是用来描述WebService的,它用XML的格式描述了WebService有哪些方法、参数类型、访问路径等等。我们要使用一个WebService肯定首先要获取它的WSDL,在VS中添加一个Web 引用时,这些工作由开发环境帮我们做了,开发环境根据WSDL文档给Web Service生成了相应的代理类供我们使用。
下面是一个HelloWorld的WebService的服务端:
public class Service : System.Web.Services.WebService
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
[WebMethod]
public DateTime HelloWorld(int i)
return DateTime.N
  其对应的WebService的WSDL文档如下:
&?xml version="1.0" encoding="utf-8"?& 2 &wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"& 3
&wsdl:types& 4
&s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/"& 5
&s:element name="HelloWorld"& 6
&s:complexType& 7
&s:sequence& 8
&s:element minOccurs="1" maxOccurs="1" name="i" type="s:int" /& 9
&/s:sequence&<span style="color:#
&/s:complexType&<span style="color:#
&/s:element&<span style="color:#
&s:element name="HelloWorldResponse"&<span style="color:#
&s:complexType&<span style="color:#
&s:sequence&<span style="color:#
&s:element minOccurs="1" maxOccurs="1" name="HelloWorldResult" type="s:dateTime" /&<span style="color:#
&/s:sequence&<span style="color:#
&/s:complexType&<span style="color:#
&/s:element&<span style="color:#
&/s:schema&<span style="color:#
&/wsdl:types&<span style="color:#
&wsdl:message name="HelloWorldSoapIn"&<span style="color:#
&wsdl:part name="parameters" element="tns:HelloWorld" /&<span style="color:#
&/wsdl:message&<span style="color:#
&wsdl:message name="HelloWorldSoapOut"&<span style="color:#
&wsdl:part name="parameters" element="tns:HelloWorldResponse" /&<span style="color:#
&/wsdl:message&<span style="color:#
&wsdl:portType name="ServiceSoap"&<span style="color:#
&wsdl:operation name="HelloWorld"&<span style="color:#
&wsdl:input message="tns:HelloWorldSoapIn" /&<span style="color:#
&wsdl:output message="tns:HelloWorldSoapOut" /&<span style="color:#
&/wsdl:operation&<span style="color:#
&/wsdl:portType&<span style="color:#
&wsdl:binding name="ServiceSoap" type="tns:ServiceSoap"&<span style="color:#
&soap:binding transport="http://schemas.xmlsoap.org/soap/http" /&<span style="color:#
&wsdl:operation name="HelloWorld"&<span style="color:#
&soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" /&<span style="color:#
&wsdl:input&<span style="color:#
&soap:body use="literal" /&<span style="color:#
&/wsdl:input&<span style="color:#
&wsdl:output&<span style="color:#
&soap:body use="literal" /&<span style="color:#
&/wsdl:output&<span style="color:#
&/wsdl:operation&<span style="color:#
&/wsdl:binding&<span style="color:#
&wsdl:binding name="ServiceSoap12" type="tns:ServiceSoap"&<span style="color:#
&soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /&<span style="color:#
&wsdl:operation name="HelloWorld"&<span style="color:#
&soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" /&<span style="color:#
&wsdl:input&<span style="color:#
&soap12:body use="literal" /&<span style="color:#
&/wsdl:input&<span style="color:#
&wsdl:output&<span style="color:#
&soap12:body use="literal" /&<span style="color:#
&/wsdl:output&<span style="color:#
&/wsdl:operation&<span style="color:#
&/wsdl:binding&<span style="color:#
&wsdl:service name="Service"&<span style="color:#
&wsdl:port name="ServiceSoap" binding="tns:ServiceSoap"&<span style="color:#
&soap:address location="http://localhost:2206/WebSite1/Service.asmx" /&<span style="color:#
&/wsdl:port&<span style="color:#
&wsdl:port name="ServiceSoap12" binding="tns:ServiceSoap12"&<span style="color:#
&soap12:address location="http://localhost:2206/WebSite1/Service.asmx" /&<span style="color:#
&/wsdl:port&<span style="color:#
&/wsdl:service&<span style="color:# &/wsdl:definitions&
一个WSDL文档由四部分组成:
  指定了WebService用到的所有数据类型,上面用到了两种数据类型,int和datetime
2、message
  指明一个操作所用到的数据类型。
  HelloWorldSoapIn是指HelloWorld的输入操作用到的数据类型,HelloWorldSoapOut是指HelloWorld的输出操作用到的数据类型。二者的element元素指出了与types中对应到的具体类型。
3、portType
  指出了这个WebService所有支持的操作,就是说有哪些方法可供调用。
  这里支持一个HelloWorld调用,它的输入和输出对应到HelloWorldSoapIn和HelloWorldSoapOut这个两个数据类型。
4、binding
  soap12:binding元素的transport指明传输协议,这里是http协议。
  operation 指明要暴露给外界调用的操作。
  use属性指定输入输出的编码方式,这里没有指定编码。
5、services
  指定服务的一些信息,主要是指定服务的访问路径。
&&&&推荐文章:
【上篇】【下篇】}

我要回帖

更多关于 soap wsdl 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信