SOAP协议

soap协议的定义

    soap即简单对象访问协议,通俗地说,它是使用http协议来发送XML格式的数据。soap=http + xml。

由于它基于http协议,所以它是能跨防火墙的。

soap协议的格式

    必须有的Envelope元素,此元素将整个XML文档标识为一条soap消息

    可选的Header元素,包含头部信息

    必须有的Body元素,包含了请求或响应的信息

    可选的Fault元素,与错误有关的信息

soap协议监控

    通过代理的方式,可以监控客户端和服务端的交换。

监控代理的配置

    在eclipse中的配置如下所示,

分别启动服务端,客户端即可看到监控情况,下面是我本机的监控

soap请求:

GET /weather?wsdl HTTP/1.1
User-Agent: Java/1.8.0_131
Host: 127.0.0.1:333
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
POST /weather HTTP/1.1
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://ws.gaoyi.smu/WeatherInterfaceImpl/queryWeatherRequest"
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
Host: 127.0.0.1:333
Connection: keep-alive
Content-Length: 205
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:queryWeather xmlns:ns2="http://ws.gaoyi.smu/"><arg0>北京</arg0></ns2:queryWeather></S:Body></S:Envelope>

soap响应:

HTTP/1.1 200 OK
Date: Sun, 08 Oct 2017 08:57:09 GMT
Transfer-encoding: chunked
Content-type: text/xml;charset=utf-8

89f
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.gaoyi.smu/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.gaoyi.smu/" name="WeatherInterfaceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.gaoyi.smu/" schemaLocation="http://127.0.0.1:333/weather?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="queryWeather">
<part name="parameters" element="tns:queryWeather"></part>
</message>
<message name="queryWeatherResponse">
<part name="parameters" element="tns:queryWeatherResponse"></part>
</message>
<portType name="WeatherInterfaceImpl">
<operation name="queryWeather">
<input wsam:Action="http://ws.gaoyi.smu/WeatherInterfaceImpl/queryWeatherRequest" message="tns:queryWeather"></input>
<output wsam:Action="http://ws.gaoyi.smu/WeatherInterfaceImpl/queryWeatherResponse" message="tns:queryWeatherResponse"></output>
</operation>
</portType>
<binding name="WeatherInterfaceImplPortBinding" type="tns:WeatherInterfaceImpl">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="queryWeather">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="WeatherInterfaceImplService">
<port name="WeatherInterfaceImplPort" binding="tns:WeatherInterfaceImplPortBinding">
<soap:address location="http://127.0.0.1:333/weather"></soap:address>
</port>
</service>
</definitions>
0

HTTP/1.1 200 OK
Date: Sun, 08 Oct 2017 08:57:09 GMT
Transfer-encoding: chunked
Content-type: text/xml; charset=utf-8

de
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:queryWeatherResponse xmlns:ns2="http://ws.gaoyi.smu/"><return>晴</return></ns2:queryWeatherResponse></S:Body></S:Envelope>
0

可以看到客户端请求服务端过程中,一共发出了两次请求,第一次是请求wsdl。第二次才是真正的数据请求~


1.1   SOAP1.1SOAP1.2区别

l  相同点:

Ø  请求发送方式相同:都是使用POST

Ø  协议内容相同:都有EnvelopeBody标签

l  不同点:

Ø  数据格式不同:content-type不同

n  SOAP1.1text/xml;charset=utf-8

n  SOAP1.2application/soap+xml;charset=utf-8

Ø     命名空间不同:

n  SOAP1.1http://schemas.xmlsoap.org/soap/envelope/

n  SOAP1.2http://www.w3.org/2003/05/soap-envelope


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值