什么是SOAP
SOAP全称Simple Object Access Protocol。它是基于XML协议的WEB服务。它对开发语言没有限制,对运行平台也没有限制。开发语言可以使用Java、C++、.Net、Python、PHP、JS(node's)等等,运行平台可以使用Linux、Windows、Unix、Mac等等。使用SOAP可以让您开发的应用程序和其它使用SOAP协议的应用程序进行交互,而不用局限其它应用程序所使用的开发语言和运行平台。SOAP也不受低层传输协议的限制,可以使用HTTP、FTP、TCP、UDP来传递。
SOAP必须使用XML格式来传递消息。满足一下格式要求的XML都可以成为SOAP:
SOAP报文中封装XML
SOAP报文中封装SOAP报文
SOAP报文头
用于识别SOAP报文请求的XML 命名空间(xmlns)
对序列化数据进行编码
SAOP使用统一的传输协议
举例
获得国内手机号码归属地数据库信息输入参数:无;返回数据:一维字符串数组(省份 城市 记录数量)。
请求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>
网友评论