01.WebService介绍

WebService定义

顾名思义就是基于Web的服务。它使用SOAP(HTTP)协议,接收和响应外部系统的某种请求。从而实现远程调用。WebService可以理解为一个对外发布的服务,提供服务文档(WSDL),供其他的系统进行调用(本质上使用的还是http方式)。

名词解释

WSDL

WebService Description Language – Web服务描述语言。通过XML形式说明服务在什么地方-地址。通过XML形式说明服务提供什么样的方法 – 如何调用。

SOAP

Simple Object Access Protocol(简单对象访问协议),SOAP作为一个基于XML语言的协议用于有网上传输数据。SOAP = 在HTTP的基础上+XML数据。SOAP是基于HTTP的,使用POST方式。SOAP的组成如下:Envelope – 必须的部分。以XML的根元素出现。Headers – 可选的。Body – 必须的。在body部分,包含要执行的服务器的方法。和发送到服务器的数据(服务器相应的数据)。

SOAP1.1请求消息体

  1. POST /WebServices/MobileCodeWS.asmx HTTP/1.1
  2. Host: webservice.webxml.com.cn
  3. Content-Type: text/xml; charset=utf-8
  4. Content-Length: length
  5. SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
  6. <?xml version="1.0" encoding="utf-8"?>
  7. <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/">
  8. <soap:Body>
  9. <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
  10. <mobileCode>string</mobileCode>
  11. <userID>string</userID>
  12. </getMobileCodeInfo>
  13. </soap:Body>
  14. </soap:Envelope>

SOAP1.1响应消息体

  1. HTTP/1.1 200 OK
  2. Content-Type: text/xml; charset=utf-8
  3. Content-Length: length
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <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/">
  6. <soap:Body>
  7. <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
  8. <getMobileCodeInfoResult>string</getMobileCodeInfoResult>
  9. </getMobileCodeInfoResponse>
  10. </soap:Body>
  11. </soap:Envelope>

SOAP1.2请求消息体

  1. POST /WebServices/MobileCodeWS.asmx HTTP/1.1
  2. Host: webservice.webxml.com.cn
  3. Content-Type: application/soap+xml; charset=utf-8
  4. Content-Length: length
  5. <?xml version="1.0" encoding="utf-8"?>
  6. <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  7. <soap12:Body>
  8. <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
  9. <mobileCode>string</mobileCode>
  10. <userID>string</userID>
  11. </getMobileCodeInfo>
  12. </soap12:Body>
  13. </soap12:Envelope>

SOAP1.2响应消息体

  1. HTTP/1.1 200 OK
  2. Content-Type: application/soap+xml; charset=utf-8
  3. Content-Length: length
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  6. <soap12:Body>
  7. <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
  8. <getMobileCodeInfoResult>string</getMobileCodeInfoResult>
  9. </getMobileCodeInfoResponse>
  10. </soap12:Body>
  11. </soap12:Envelope>

SOAP1.1和1.2版本关系

SOAP1.2客户端兼容1.1和1.2的SOAP服务端,SOAP1.1客户端只能用于1.2的服务端。wsimport命令只能识别1.1的WSDL文档,wsdl2java可以识别1.1和1.2的文档,后者在实际开发中使用更多。
posted @ 2017-02-24 12:39  Wesly186  阅读(128)  评论(0编辑  收藏  举报