“Web Services:SOAP”的版本间差异
跳到导航
跳到搜索
(建立内容为“category:SOAP == 关于 == 一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素: * 必需的 '''Envelope''' 元素,可把此 XML 文…”的新页面) |
无编辑摘要 |
||
第1行: | 第1行: | ||
[[category: | [[category:Web Services]] | ||
== 关于 == | == 关于 == | ||
SOAP 是一种简单的'''基于 XML 的协议''',它使应用程序'''通过 HTTP 来交换信息'''。 | |||
简而言之:'''SOAP 是用于访问网络服务的协议'''。 | |||
=== 为什么使用 SOAP? === | |||
<pre> | |||
对于应用程序开发来说,使程序之间进行因特网通信是很重要的。 | |||
目前的应用程序通过使用远程过程调用(RPC)在诸如 DCOM 与 CORBA 等对象之间进行通信,但是 HTTP 不是为此设计的。RPC 会产生兼容性以及安全问题;防火墙和代理服务器通常会阻止此类流量。 | |||
通过 HTTP 在应用程序间通信是更好的方法,因为 HTTP 得到了所有的因特网浏览器及服务器的支持。SOAP 就是被创造出来完成这个任务的。 | |||
</pre> | |||
SOAP 提供了一种标准的方法,使得'''运行在不同的操作系统并使用不同的技术和编程语言的应用程序可以互相进行通信'''。 | |||
=== Microsoft 和 SOAP === | |||
SOAP 是微软 .net 架构的关键元素,用于未来的因特网应用程序开发。 | |||
== 语法 == | |||
一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素: | 一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素: | ||
* 必需的 '''Envelope''' 元素,可把此 XML 文档'''标识为一条 SOAP 消息'''; | * 必需的 '''Envelope''' 元素,可把此 XML 文档'''标识为一条 SOAP 消息'''; | ||
第13行: | 第32行: | ||
以及针对 SOAP 编码和数据类型的默认命名空间: http://www.w3.org/2001/12/soap-encoding | 以及针对 SOAP 编码和数据类型的默认命名空间: http://www.w3.org/2001/12/soap-encoding | ||
== 语法规则 == | === 语法规则 === | ||
重要的语法规则: | 重要的语法规则: | ||
* SOAP 消息必须用 XML 来编码 | * SOAP 消息必须用 XML 来编码 | ||
第21行: | 第40行: | ||
* SOAP 消息不能包含 XML 处理指令 | * SOAP 消息不能包含 XML 处理指令 | ||
== SOAP 消息的基本结构 == | === SOAP 消息的基本结构 === | ||
<syntaxhighlight lang="xml" highlight=""> | <syntaxhighlight lang="xml" highlight=""> | ||
<?xml version="1.0"?> | <?xml version="1.0"?> | ||
第41行: | 第60行: | ||
</soap:Envelope> | </soap:Envelope> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Envelope 元素 == | |||
强制使用的 SOAP 的 Envelope 元素是 SOAP 消息的根元素。 | |||
* 它可把 XML 文档定义为 SOAP 消息。 | |||
示例: | |||
<syntaxhighlight lang="xml" highlight=""> | |||
<?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"> | |||
... | |||
Message information goes here | |||
... | |||
</soap:Envelope> | |||
</syntaxhighlight> | |||
=== xmlns:soap 命名空间 === | |||
SOAP 消息必须拥有与命名空间 "http://www.w3.org/2001/12/soap-envelope" 相关联的一个 Envelope 元素。 | |||
* 如果使用了不同的命名空间,应用程序会发生错误,并抛弃此消息。 | |||
=== encodingStyle 属性 === | |||
SOAP 的 encodingStyle 属性用于'''定义在文档中使用的数据类型'''。 | |||
* 此属性可出现在任何 SOAP 元素中,并会被应用到元素的内容及元素的所有子元素上。 | |||
* SOAP 消息没有默认的编码方式。 | |||
语法: | |||
<syntaxhighlight lang="xml" highlight=""> | |||
soap:encodingStyle="URI" | |||
</syntaxhighlight> | |||
实例: | |||
<syntaxhighlight lang="xml" highlight=""> | |||
<?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"> | |||
... | |||
Message information goes here | |||
... | |||
</soap:Envelope> | |||
</syntaxhighlight> | |||
== Header 元素 == | |||
== Body 元素 == | |||
== Fault 元素 == | |||
== HTTP Binding == | |||
== 实例 == | |||
== 参考 == | |||
# [https://www.runoob.com/soap/soap-tutorial.html 菜鸟教程:SOAP 教程] |
2021年6月1日 (二) 02:53的版本
关于
SOAP 是一种简单的基于 XML 的协议,它使应用程序通过 HTTP 来交换信息。
简而言之:SOAP 是用于访问网络服务的协议。
为什么使用 SOAP?
对于应用程序开发来说,使程序之间进行因特网通信是很重要的。 目前的应用程序通过使用远程过程调用(RPC)在诸如 DCOM 与 CORBA 等对象之间进行通信,但是 HTTP 不是为此设计的。RPC 会产生兼容性以及安全问题;防火墙和代理服务器通常会阻止此类流量。 通过 HTTP 在应用程序间通信是更好的方法,因为 HTTP 得到了所有的因特网浏览器及服务器的支持。SOAP 就是被创造出来完成这个任务的。
SOAP 提供了一种标准的方法,使得运行在不同的操作系统并使用不同的技术和编程语言的应用程序可以互相进行通信。
Microsoft 和 SOAP
SOAP 是微软 .net 架构的关键元素,用于未来的因特网应用程序开发。
语法
一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素:
- 必需的 Envelope 元素,可把此 XML 文档标识为一条 SOAP 消息;
- 可选的 Header 元素,包含头部信息;
- 必需的 Body 元素,包含所有的调用和响应信息;
- 可选的 Fault 元素,提供有关在处理此消息所发生错误的信息;
所有以上的元素均被声明于针对 SOAP 封装的默认命名空间中: http://www.w3.org/2001/12/soap-envelope
以及针对 SOAP 编码和数据类型的默认命名空间: http://www.w3.org/2001/12/soap-encoding
语法规则
重要的语法规则:
- SOAP 消息必须用 XML 来编码
- SOAP 消息必须使用 SOAP Envelope 命名空间
- SOAP 消息必须使用 SOAP Encoding 命名空间
- SOAP 消息不能包含 DTD 引用
- SOAP 消息不能包含 XML 处理指令
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>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
Envelope 元素
强制使用的 SOAP 的 Envelope 元素是 SOAP 消息的根元素。
- 它可把 XML 文档定义为 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">
...
Message information goes here
...
</soap:Envelope>
xmlns:soap 命名空间
SOAP 消息必须拥有与命名空间 "http://www.w3.org/2001/12/soap-envelope" 相关联的一个 Envelope 元素。
- 如果使用了不同的命名空间,应用程序会发生错误,并抛弃此消息。
encodingStyle 属性
SOAP 的 encodingStyle 属性用于定义在文档中使用的数据类型。
- 此属性可出现在任何 SOAP 元素中,并会被应用到元素的内容及元素的所有子元素上。
- SOAP 消息没有默认的编码方式。
语法:
soap:encodingStyle="URI"
实例:
<?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">
...
Message information goes here
...
</soap:Envelope>