soap soapenv SOAP-ENV 区别

soap soapenv SOAP-ENV 区别

请求代码

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <helloWorldResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <helloWorldReturn xsi:type="xsd:string">Hello World! This  is Test!</helloWorldReturn>
  </helloWorldResponse>
 </soapenv:Body>
</soapenv:Envelope>

有时soapevn 是大写: SOAP-ENV,这完全是命名空间的定义

这个属于XML基础知识。
带有冒号的xml标签用于声明xml的标签元素的命名空间。

为什么要使用命名空间呢?这是因为XML文档中同一个标签名可能有着不同的含义。例如<table>这个标签,一般我们知道它是一个网页上的表格,如果一个家具商,它当然认为这表示一张桌子了。有时即使是在一个XML文件内也可能有这样的命名冲突。因此XML规范制定者们引入了名字空间的概念。具体做法就是先用xmlns:xxx 声明一个命名空间,这样在标签的前面加个前缀并与标签本身的名字用冒号隔开。这就是SOAP的XML文本中冒号和xmlns满天飞的由来。

这个前缀soapenv 应该而且只需要与xmlns:后面的东西完全一样。换句话说。你可以叫soapenv 也可以叫SOAP-ENV或其他任何你喜欢的名字,但后面的 xmlns:xxx=yyyy这个xxx也必须叫这个名字。后面的这个yyyy可是固定的内容。
XML规范还规定了,命名空间是向下包含的。除非特别另外声明,子节点的命名空间默认就是它的父节点的命名空间,这样可以减少书写的麻烦。

扩展

** 什么是 SOAP? **

SOAP 指简易对象访问协议
SOAP 是一种通信协议
SOAP 用于应用程序之间的通信
SOAP 是一种用于发送消息的格式
SOAP 被设计用来通过因特网进行通信
SOAP 独立于平台
SOAP 独立于语言
SOAP 基于 XML
SOAP 很简单并可扩展
SOAP 允许您绕过防火墙
SOAP 将被作为 W3C 标准来发展
** 语法规则 **

SOAP 消息必须用 XML 来编码
SOAP 消息必须使用 SOAP Envelope 命名空间
SOAP 消息必须使用 SOAP Encoding 命名空间
SOAP 消息不能包含 DTD 引用
SOAP 消息不能包含 XML 处理指令
** SOAP消息举例 **

请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://service.zlb.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <q0:sayHello>
      <arg0>hello</arg0>
    </q0:sayHello>
  </soapenv:Body>
</soapenv:Envelope>

响应

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:sayHelloResponse xmlns:ns2="http://service.zlb.com/">
<return>hello hello</return>
</ns2:sayHelloResponse>
</soap:Body>
</soap:Envelope>

soap和soapenv xml例子

soap是这样的:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
    <soap:Header/>
    <soap:Body>
        <tem:BillnoteClipInitialization>
            <tem:json>
            {}
            </tem:json>
        </tem:BillnoteClipInitialization><!--  -->
    </soap:Body>
</soap:Envelope>

soapenv是这样的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
    <soapenv:Header/>
    <soapenv:Body>
        <tem:BillnoteClip>
            <tem:json>
            {}
            </tem:json>
            <tem:type>set</tem:type>
        </tem:BillnoteClip>
    </soapenv:Body>
</soapenv:Envelope>

参考文章:

https://blog.csdn.net/enetor1/article/details/40856897

https://www.jianshu.com/p/c3ef663c6101

https://blog.csdn.net/enthan809882/article/details/103941858

猜你喜欢

转载自www.cnblogs.com/soymilk2019/p/12188518.html