【WebService】8.SOAP协议深入详解

我们上次使用客户端向服务器端发送了两次WebService请求,分别是

(1)sayHi请求
向服务端发送一个name,然后服务端回复“你好”和对应的name以及现在的时间。

(2)getAllCats请求
获取所有的宠物猫的数据。

报文大致截图:


我们使用拦截器拦截了以上两个请求的请求报文和回复报文,我们接下来通过一一剖析来深入理解SOAP。

A.对于sayHi操作:
传入消息
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope">
    <S:Body>
        <ns2:sayHi xmlns:ns2="http://ws.cxf.java.org">
         <arg0>孙悟空</arg0>
        </ns2:sayHi>
    </S:Body>
</S:Envelope>

传出消息
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns2:sayHiResponse xmlns:ns2="http://ws.cxf.java.org">
         <return>孙悟空,您好现在的时间是:Mon Aug 01 18:33:53 CST 2016</return>
        </ns2:sayHiResponse>
    </soap:Body>
</soap:Envelope>

B.对于getAllCats操作
传入消息
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope">
    <S:Body>
        <ns2:getAllCats xmlns:ns2="http://ws.cxf.java.org"/>
    </S:Body>
</S:Envelope>

传出消息
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns2:getAllCatsResponse xmlns:ns2="http://ws.cxf.java.org">
         <return>
                <entries>
            <key>第1个</key>
                    <value>
            <color>黑色</color>
            <id>1</id>
            <name>花花</name>
                    </value>
        </entries>
        <entries>
            <key>第2个</key>
                    <value>
            <color>白色</color>
            <id>2</id>
            <name>毛球</name>
                    </value>
        </entries>
        <entries>
            <key>第3个</key>
                    <value>
            <color>黄色</color>
            <id>3</id>
            <name>丁丁</name>
                    </value>
        </entries>
        <entries>
            <key>第4个</key>
                    <value>
            <color>灰色</color>
            <id>4</id>
            <name>咪咪</name>
                    </value>
        </entries>
         </return>
        </ns2:getAllCatsResponse>
    </soap:Body>
</soap:Envelope>

以上是请求成功的返回信息,当我们启动服务端的时候,在浏览器输入提供服务的路径,而不输入服务名称,这个时候浏览器就会显示提示错误的soap信息:


其实还有一个header元素,这个是自定义的,用来携带其他信息(如用户名密码)。

我们就可以分析出来SOAP信息的大致格式:


我们其实可以看出来,body标签对的内容其实是和WSDL格式是对应的。

所以我们总结一下SOAP:
Header
    Header是可选的,由开发人员控制添加。
Body
    Body元素总是默认的,Body元素里可能有两种情况:
    --当WebService交互正确时,Body元素里的内容由WSDL控制。
    --当WebService交互出错时,Body元素里的内容为Fault子元素。
转载请注明出处:http://blog.csdn.net/acmman/article/details/52269996
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

光仔December

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值