SOAP 消息没有默认的编码方式

发布时间:2025-06-24 19:45:51  作者:北方职教升学中心  阅读量:543


这三个属性是:actor、

注意: 所有 Header 元素的直接子元素必须是合格的命名空间。

SOAP 在默认的命名空间中 (“http://www.w3.org/2001/12/soap-envelope”) 定义了三个属性。

2、
目录
  • SOAP
    • 1、它还支持从消息系统到远程过程调用(RPC)等大量的应用程序。mustUnderstand 属性

SOAP 的 mustUnderstand属性可用于标识标题项对于要对其进行处理的接收者来说是强制的还是可选的。Content-Type

SOAP 的请求和响应的 Content-Type 头可定义消息的 MIME 类型,以及用于请求或响应的 XML 主体的字符编码(可选)。语法规则

  • SOAP 消息必须用 XML 来编码
  • SOAP 消息必须使用 SOAP Envelope 命名空间
  • SOAP 消息必须使用 SOAP Encoding 命名空间
  • SOAP 消息不能包含 DTD 引用
  • SOAP 消息不能包含 XML 处理指令
2.3、Fault元素
  • 7、组成部分
  • 2.2、Header元素
  • 可选的 SOAP Header 元素可包含有关 SOAP 消息的应用程序专用信息(比如认证、概述

    SOAP即(Simple Object Access Protocol)简单对象访问协议是交换数据的一种协议规范,是一种轻量的、这些被定义在 SOAP 头部的属性可定义容器如何对 SOAP 消息进行处理。Body元素

  • 6、在一条 SOAP 消息中,Fault 元素只能出现一次。
  • Client:消息被不正确地构成,或包含了不正确的信息。SOAP 消息没有默认的编码方式。mustUnderstand 属性
  • 4.2、此属性可出现在任何 SOAP 元素中,并会被应用到元素的内容及元素的所有子元素上。如果已提供了 Fault 元素,则它必须是 Body 元素的子元素。Envelope元素
    • 3.1、概述
    • 2、SOAP Body 元素的直接子元素可以是合格的命名空间。actor 属性

      通过沿着消息路径经过不同的端点,SOAP 消息可从某个发送者传播到某个接收者。

      语法:

      soap:mustUnderstand="0|1"

      实例:

      <?xml version="1.0"?><soap:Envelopexmlns: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="http://www.w3schools.com/transaction/"  soap:mustUnderstand="1">234  </m:Trans></soap:Header>......</soap:Envelope>
      4.2、 mustUnderstand 以及encodingStyle。Body元素

      SOAP Body 元素可包含打算传送到消息最终端点的实际 SOAP 消息。

      SOAP 消息没有默认的编码方式。

      语法:

      soap:encodingStyle="URI"

      实例:

      <?xml version="1.0"?><soap:Envelopexmlns: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>

      4、

      语法:

      soap:actor="URI"

      实例:

      <?xml version="1.0"?><soap:Envelopexmlns: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="http://www.w3schools.com/transaction/"  soap:actor="http://www.w3schools.com/appml/">234  </m:Trans></soap:Header>......</soap:Envelope>

      4.3、
    • Server:服务器有问题,因此无法处理进行下去。

      而一个 SOAP 响应应该类似这样:

      <?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body>  <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">    <m:Price>1.90</m:Price>  </m:GetPriceResponse></soap:Body></soap:Envelope>

      6、

      <?xml version="1.0"?><soap:Envelopexmlns: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>

      3.1、

      语法:

      soap:encodingStyle="URI"

      5、Header元素

      • 4.1、Envelope元素

        SOAP 的 Envelope 元素是 SOAP 消息的根元素。
        HTTP POST 请求规定至少两个 HTTP 头:

        • Content-Type
        • Content-Length
        7.1、假如此接收者无法认可此元素,则在处理此头部时必须失效。语法规则
      • 2.3、实例

    SOAP

    1、

    SOAP 可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议(HTTP),简单邮件传输协议(SMTP),多用途网际邮件扩充协议(MIME)。

    以及针对 SOAP 编码和数据类型的默认命名空间:
    http://www.w3.org/2001/12/soap-encoding。基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。actor 属性

  • 4.3、基本结构

    SOAP消息的基本结构如下:

    <?xml version="1.0"?><soap:Envelopexmlns: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>

    3、

    4.1、SOAP使用基于XML的数据结构和超文本传输协议(HTTP)的组合定义了一个标准的方法来使用Internet上各种不同操作环境中的分布式对象。请注意,上面的 m:GetPrice 和 Item 元素是应用程序专用的元素。
  • 7、encodingStyle 属性

    SOAP 的 encodingStyle 属性用于定义在文档中使用的数据类型。此功能的命名空间被定义在此地址中: “http://www.example.org/stock”

    SOAP请求:

    POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPrice>    <m:StockName>IBM</m:StockName>  </m:GetStockPrice></soap:Body></soap:Envelope>

    SOAP响应:

    HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body xmlns:m="http://www.example.org/stock">  <m:GetStockPriceResponse>    <m:Price>34.5</m:Price>  </m:GetStockPriceResponse></soap:Body></soap:Envelope>

    SOAP 的 actor 属性可被用于将 Header 元素寻址到一个特定的端点。encodingStyle 属性

  • 5、

    <?xml version="1.0"?><soap:Envelopexmlns: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="http://www.w3schools.com/transaction/"  soap:mustUnderstand="1">234  </m:Trans></soap:Header>......</soap:Envelope>

    上面的例子包含了一个带有一个 “Trans” 元素的头部,它的值是 234,此元素的 “mustUnderstand” 属性的值是 “1”。xmlns:soap 命名空间

    SOAP 消息必须拥有与命名空间 "http://www.w3.org/2001/12/soap-envelope"相关联的一个 Envelope 元素。如果 Header 元素被提供,则它必须是 Envelope 元素的第一个子元素。SOAP HTTP Binding

    指的是遵守 SOAP 编码规则的 HTTP 请求/响应。此属性可出现在任何 SOAP 元素中,并会被应用到元素的内容及元素的所有子元素上。

    语法

    Content-Length: bytes

    实例:

    POST /item HTTP/1.1Content-Type: application/soap+xml; charset=utf-8Content-Length: 250

    8、

    语法:

    Content-Type: MIMEType; charset=character-encoding

    实例:

    POST /item HTTP/1.1Content-Type: application/soap+xml; charset=utf-8

    7.2、

    假如向 Header 元素的某个子元素添加了"mustUnderstand="1",则它可指示处理此头部的接收者必须认可此元素。支付等)。基本结构

  • 3、Fault元素

    SOAP Fault 元素用于指示错误消息。

    HTTP + XML = SOAP
    SOAP 请求可能是 HTTP POSTHTTP GET请求。xmlns:soap 命名空间

  • 3.2、语法
    2.1、如果使用了不同的命名空间,应用程序会发生错误,并抛弃此消息。encodingStyle 属性

    SOAP 的 encodingStyle 属性用于定义在文档中使用的数据类型。encodingStyle 属性

  • 4、组成部分

    一条 SOAP 消息就是一个普通的 XML 文档,包含下列元素:

    • 必需的Envelope元素,可把此 XML 文档标识为一条 SOAP 消息
    • 可选的Header元素,包含头部信息
    • 必需的Body元素,包含所有的调用和响应信息
    • 可选的Fault元素,提供有关在处理此消息所发生错误的信息

    所有以上的元素均被声明于针对 SOAP 封装的默认命名空间中:http://www.w3.org/2001/12/soap-envelope

    <?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Body>  <m:GetPrice xmlns:m="http://www.w3schools.com/prices">    <m:Item>Apples</m:Item>  </m:GetPrice></soap:Body></soap:Envelope>

    上面的例子请求苹果的价格。语法

    • 2.1、并非 SOAP 消息的所有部分均打算传送到 SOAP 消息的最终端点,不过,另一个方面,也许打算传送给消息路径上的一个或多个端点。

      SOAP 的 Fault 元素拥有下列子元素:

      • <faulcode>:供识别故障的代码
      • <faultstring>:可供人阅读的有关故障的说明
      • <faultactor>:有关是谁引发的故障的信息
      • <detail>:存留涉及Body元素的应用程序专用错误信息

      SOAP Fault代码:

      • VersionMismatch:SOAP Envelope 元素的无效命名空间被发现
      • MustUnderstand:Header 元素的一个直接子元素(带有设置为 “1” 的 mustUnderstand 属性)无法被理解。

        3.2、它们并不是 SOAP 标准的一部分。Content-Length

        SOAP 的请求和响应的 Content-Length 头规定请求或响应主体的字节数。Content-Length

    • 8、简单的、实例

      在下面的例子中,一个 GetStockPrice 请求被发送到了服务器。SOAP HTTP Binding

      • 7.1、它可把 XML 文档定义为 SOAP 消息。此请求有一个 StockName 参数,而在响应中则会返回一个 Price 参数。Content-Type
      • 7.2、

        2.2、