SMTP Transport Binding for SOAP

SOAP 除了可以 bind 到 HTTP 上外, 也可以 bind 到 SMTP 上. 其实个人感觉, SOAP bind 到 SMTP 上的场景很少会使用到, 通常限于 one-way operation (比如通知等不需要响应). 如果需要实现 request/response, 那么是需要多做一些工作的(下文会有叙述).

soap:binding element 的 transport 属性需指定一个 http://xxx(例如:http://schemas.xmlsoap.org/soap/smtp) URL 来表明所要 binding 的 protocol. 似乎这个 URL 是任意形式, 只要能让调用方知道要使用什么协议即可. 在 soap:address 要给定 mailto:xxxx@xxx.xxx 这样形式的 URI.

    <service name="StockQuoteServiceBinding_service">
        <port name="StockQuoteServiceBinding_port"
                binding="binding:StockQuoteServiceBinding">
            <soap:address location="mailto:getQuote@test.com"/>
        </port>
    </service>

注意: 在 soap:address element 中, 可能会有一些扩展元素, 例如smtp server, smtp username, smtp password, etc.

在需要 request / response 语义情况下, 需使用标准的 Message-Id 和 In-Reply-To SMTP header 来实现这一目标. 请求包含一个 Message-Id header, 相应的响应则在 In-Reply-To header 中使用请求的 Message-Id header 值, 同时也创建一个新的 Message-Id header. 这样, 在请求与响应之间便建立了关联.

请求:

To: <soap@example.org>
 From: <soap@client.com>
 Reply-To: <soap@client.com>
 Date: Tue, 15 Nov 2001 23:27:00 -0700
 Message-Id: <1F75D4D515C3EC3F34FEAB51237675B5@client.com>
 MIME-Version: 1.0
 Content-Type: text/xml; charset=utf-8
 Content-Transfer-Encoding: QUOTED-PRINTABLE

 <?xml version=3D"1.0" encoding=3D"UTF-8"?>
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle=3D"http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENC=3D"http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV=3D"http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"
 xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
 <SOAP-ENV:Body>
 <m:echoString xmlns:m=3D"http://soapinterop.org/">
 <inputString>get your SOAP over SMTP here !</inputString>
 </m:echoString>
 </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

响应:

To: <soap@client.com>
 From: <soap@example.org>
 Date: Tue, 13 Nov 2001 23:27:00 -0700
 In-Reply-To: <1F75D4D515C3EC3F34FEAB51237675B5@client.com>
 Message-Id: <FF75D4D515C3EC3F34FEAB51237675B5@soap.example.org>
 MIME-Version: 1.0
 Content-Type: TEXT/XML; charset=utf-8
 Content-Transfer-Encoding: QUOTED-PRINTABLE

 <?xml version=3D"1.0" encoding=3D"UTF-8"?>
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle=3D"http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENC=3D"http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV=3D"http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema"
 xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance">
 <SOAP-ENV:Body>
 <m:echoStringResponse xmlns:m=3D"http://soapinterop.org/">
 <return>get your SOAP over SMTP here !</return>
 </m:echoStringResponse>
 </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

Resources:

  1. http://www.pocketsoap.com/specs/smtpbinding/
  2. http://people.apache.org/~pzf/SMTPBase64Binding.html
By javafuns on July 19, 2009 at 23:37 · Views: 207 · Permalink
Categorized in: SOA · Tagged with: , , , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply


  • Highest Rated

  • My PicasaPhotos

    IMG_0664.JPG

    IMG_0543.JPG

    IMG_0674.JPG

  • RSS My del.icio.us

  • My RSS