儘管可以用多種技術來實現面向服務的架構(SOA),但最常用的仍是基於 Web 服務的實現,而這意味著要用到 XML。SOAP 與 REST 是實現 Web 服務最流行的兩種方法,兩者都建立在 XML 之上。
舉例來說,把下面的 SOAP 文檔作為 Web 請求發送,就能向 Google Web 服務提出查詢請求:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="https://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="https://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="https://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"
SOAP-ENV:encodingStyle="https://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="xsd:string">00000000000000000000000000000000</key>
<q xsi:type="xsd:string">death star trash compactor</q>
<start xsi:type="xsd:int">0</start>
<maxResults xsi:type="xsd:int">10</maxResults>
<filter xsi:type="xsd:boolean">true</filter>
<restrict xsi:type="xsd:string"></restrict>
<safeSearch xsi:type="xsd:boolean">false</safeSearch>
<lr xsi:type="xsd:string"></lr>
<ie xsi:type="xsd:string">latin1</ie>
<oe xsi:type="xsd:string">latin1</oe>
</ns1:doGoogleSearch>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
這裡可以看到 SOAP 信封(envelope),它是 Web 服務引擎能夠理解的標準格式。而消息的內容(本例中即 doGoogleSearch 元素)被稱為有效載荷(payload),由即將被 Web 服務處理的信息組成——包括搜索關鍵字、起始位置、返回結果數量等參數。
正是這種以 XML 為基礎的消息格式,讓不同平台、不同語言構建的系統能夠互操作,從而支撐起 SOA 所追求的信息與數據交換能力。