什么是SOAP
SOAP全稱Simple Object Access Protocol。它是基于XML協(xié)議的WEB服務。它對開發(fā)語言沒有限制,對運行平臺也沒有限制。開發(fā)語言可以使用Java、C++、.Net、Python、PHP、JS(node's)等等,運行平臺可以使用Linux、Windows、Unix、Mac等等。使用SOAP可以讓您開發(fā)的應用程序和其它使用SOAP協(xié)議的應用程序進行交互,而不用局限其它應用程序所使用的開發(fā)語言和運行平臺。SOAP也不受低層傳輸協(xié)議的限制,可以使用HTTP、FTP、TCP、UDP來傳遞。
SOAP必須使用XML格式來傳遞消息。滿足一下格式要求的XML都可以成為SOAP:
SOAP報文中封裝XML
SOAP報文中封裝SOAP報文
SOAP報文頭
用于識別SOAP報文請求的XML 命名空間(xmlns)
對序列化數(shù)據(jù)進行編碼
SAOP使用統(tǒng)一的傳輸協(xié)議
舉例
獲得國內(nèi)手機號碼歸屬地數(shù)據(jù)庫信息輸入?yún)?shù):無;返回數(shù)據(jù):一維字符串數(shù)組(省份 城市 記錄數(shù)量)。
請求SOAP報文和響應SOAP報文
POST /WebServices/MobileCodeWS.asmx HTTP/1.1
Host: ws.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getDatabaseInfo"
<?xml?version="1.0" encoding="utf-8"?>
<soap:Envelope?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getDatabaseInfo?xmlns="http://WebXml.com.cn/"?/>
</soap:Body>
</soap:Envelope
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml?version="1.0" encoding="utf-8"?>
<soap:Envelope?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getDatabaseInfoResponse?xmlns="http://WebXml.com.cn/">
<getDatabaseInfoResult>
<string>string</string>
<string>string</string>
</getDatabaseInfoResult>
</getDatabaseInfoResponse>
</soap:Body>
</soap:Envelope>