开发学院

您的位置:首页>教程>正文

教程正文

SOAP 传输

SOAP 传输

SOAP不与任何传输协议相关联。SOAP可以通过SMTP、FTP、mqseries或msmq等传输。

SOAP规范仅包括有关http的详细信息,http仍然是最流行的soap传输方式。

使用http的SOAP

很合理地,soap请求是通过http请求发送的,而soap响应在http响应的内容中返回。虽然soap请求可以通过http get方式发送,但是规范只包括http post的详细信息。

此外,需要http请求和响应才能将其内容类型设置为text/xml.。

SOAP规范要求客户端必须提供SOAPAction标头,但是SOAPAction头的实际值取决于SOAP服务器实现。

例如,要访问由XMethods承载的AltaVista BabelFish翻译服务,必须指定以下作为SOAPAction header。

urn:xmethodsBabelFish#BabelFish

即使服务器不需要完整的soapaction标头,客户端也必须指定空字符串(" " )或null值。例如,

SOAPAction: ""
SOAPAction:

以下是通过http发送到XMethods Babelfish 翻译服务的示例请求:

POST /perl/soaplite.cgi HTTP/1.0
Host: services.xmethods.com
Content-Type: text/xml; charset=utf-8
Content-Length: 538
SOAPAction: "urn:xmethodsBabelFish#BabelFish"
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <SOAP-ENV:Body>
      <ns1:BabelFish xmlns:ns1="urn:xmethodsBabelFish" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <translationmode xsi:type="xsd:string">en_fr</translationmode>
         <sourcedata xsi:type="xsd:string">Hello, world!</sourcedata>
      </ns1:BabelFish>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

注意内容类型和soapaction标题。还要注意,babelfish方法需要两个字符串参数。将英语翻译成法语。

以下是XMethods的回复。

HTTP/1.1 200 OK
Date: Sat, 09 Jun 2001 15:01:55 GMT
Server: Apache/1.3.14 (Unix) tomcat/1.0 PHP/4.0.1pl2
SOAPServer: SOAP::Lite/Perl/0.50
Cache-Control: s-maxage=60, proxy-revalidate
Content-Length: 539
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
   <SOAP-ENV:Body>
      <namesp1:BabelFishResponse xmlns:namesp1="urn:xmethodsBabelFish">
      <return xsi:type="xsd:string">Bonjour, monde!</return>
      </namesp1:BabelFishResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

通过http发送的SOAP响应需要遵循相同的http状态代码。例如,200的状态代码表示成功的响应。500表示内部服务器错误,并且SOAP响应包括故障元素。