微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

webservice快速入门-SOAP和WSDL三

什么是SOAP?SOAP:Simple Object Access Protocol

以下是百度的结果:

SOAP:简单对象访问协议,简单对象访问协议(SOAP)是一种轻量的、简单的、基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息。 SOAP 可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议( HTTP),简单邮件传输协议(SMTP),多用途网际邮件扩充协议(MIME)。它还支持消息系统到远程过程调用(RPC)等大量的应用程序

说白了,它就是一种基于XML传输数据的协议,为什么基于XML,因为这样可以确保不同平台,语言的通信,也就是经常听到的导构平台之前的通信。

我们常见的json,xml其实都可以理解为是soap的实现

我们来看一下之前的WSDL文件,访问:http://localhost:7777/tudou?wsdl如下:

This XML file does not appear to have any style @R_265_4045@ion associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
-->
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
-->
<deFinitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.ws.platform.whaty.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://server.ws.platform.whaty.com/" name="MyServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://server.ws.platform.whaty.com/" schemaLocation="http://localhost:7777/tudou?xsd=1"/>
</xsd:schema>
</types>
<message name="minus">
<part name="parameters" element="tns:minus"/>
</message>
<message name="minusResponse">
<part name="parameters" element="tns:minusResponse"/>
</message>
<message name="add">
<part name="parameters" element="tns:add"/>
</message>
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
<portType name="IMyservice">
<operation name="minus">
<input message="tns:minus"/>
<output message="tns:minusResponse"/>
</operation>
<operation name="add">
<input message="tns:add"/>
<output message="tns:addResponse"/>
</operation>
</portType>
<binding name="MyServiceImplPortBinding" type="tns:IMyservice">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="minus">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="add">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MyServiceImplService">
<port name="MyServiceImplPort" binding="tns:MyServiceImplPortBinding">
<soap:address location="http://localhost:7777/tudou"/>
</port>
</service>
</deFinitions>

我们把节点收起来看得更清楚点:


很清楚的看到这个wsdl分为type,message,porttype,binding,service这5部分。

type:用来定义访问的类型,一个类型对应我们服务端接口的一个方法一个类型对应我们接口的一个返回值。我们可以看到上面的wsdl中有一个schemaLocation="http://localhost:7777/tudou?xsd=1"的玩意,我们直接在浏览器访问一下它。

This XML file does not appear to have any style @R_265_4045@ion associated with it. The document tree is shown below.
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
-->
<xs:schema xmlns:tns="http://server.ws.platform.whaty.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://server.ws.platform.whaty.com/">
<xs:element name="add" type="tns:add"/>
<xs:element name="addResponse" type="tns:addResponse"/>
<xs:element name="minus" type="tns:minus"/>
<xs:element name="minusResponse" type="tns:minusResponse"/>
<xs:complexType name="add">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="minus">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="minusResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
看到complexType了没有。如果你学了schema和dtd,你就应该知道这实际就是一种类型,下面是相应的子节点,可能还有一些约束。

message:SOAP,也就是被封装成一个对象的形式,实际上是以XML的形式展现的。里面就是传递的我们的数据。

portType:就是对应我们的操作了。可以看到operation这个单词吧。

binding:指定消息所使用的格式。Literal就是不在SOAP消息中表明数据类型,而通过其它方式获知数据类型,这种方式是开发包相关的,没有什么标准;如<x>50</x>,单从SOAP消息,你无法判断50是数字还是字符串。详见:

http://blog.csdn.net/jackyrongvip/article/details/4608014

而它里面的style="Document"中Document就是将SOAP请求和响应,或者说输入输出定义为XML元素,有严格的Schema("document" style means the messages in and out of the service are exactly as they are describe by the XML Schema in the WSDL).

service:指定服务发布的名称

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐