基于Rest的Web Service架构

1,425 views
1,353 views

Published on

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,425
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

基于Rest的Web Service架构

  1. 1. 基于 REST 的 WebService 架构 王简之
  2. 2. What & Why Webservice ?
  3. 3. Browser HTTP HTML Web Server M V C Basic Web Architecture Logical Control Visual Control
  4. 4. HTTP HTML Browser Web Server M V Basic Web Architecture VC Service Service VC
  5. 5. Web Service <ul><li>Web 服务是一种面向服务的架构的技术,通过标准的 Web 协议提供服务,目的是保证不同平台的应用服务可以互操作。 </li></ul><ul><li>WS-*, SOA, Big Webservice </li></ul><ul><li>RESTful style </li></ul>
  6. 6. WS-* <ul><li>WSDL </li></ul><ul><li>SOAP </li></ul><ul><li>UDDI </li></ul>
  7. 7. Client HTTP HTML Web Server WS- * WSDL XML SOAP Browser HTTP HTML Web Server JSON PO-XML HTML REST WSDL Recognizable HTTP Response & Request
  8. 8. <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <wsdl:definitions xmlns=&quot;...&quot; xmlns:soap=&quot;...&quot; xmlns:tns=&quot;...&quot; xmlns:x1=&quot;...&quot; xmlns:wsdl=&quot;...&quot; xmlns:xsd=&quot;...&quot; targetNamespace=&quot;...&quot; name=&quot;HelloWorld&quot;> <wsdl:types> <schema targetNamespace=&quot;...&quot; xmlns=&quot;...&quot; xmlns:x1=&quot;...&quot; elementFormDefault=&quot;qualified&quot;> <element name=&quot;greetMeSometime&quot;> <complexType> <sequence> <element name=&quot;requestType&quot; type=&quot;xsd:string&quot;/> </sequence> </complexType> </element> <element name=&quot;greetMeSometimeResponse&quot;> <complexType> <sequence> <element name=&quot;responseType&quot; type=&quot;xsd:string&quot;/> </sequence> </complexType> </element> </schema> </wsdl:types> <wsdl:message name=&quot;greetMeSometimeRequest&quot;> <wsdl:part name=&quot;in&quot; element=&quot;x1:greetMeSometime&quot;/> </wsdl:message> <wsdl:message name=&quot;greetMeSometimeResponse&quot;> <wsdl:part name=&quot;out&quot; element=&quot;x1:greetMeSometimeResponse&quot;/> </wsdl:message> <wsdl:portType name=&quot;GreeterAsync&quot;> <wsdl:operation name=&quot;greetMeSometime&quot;> <wsdl:input name=&quot;greetMeSometimeRequest&quot; message=&quot;tns:greetMeSometimeRequest&quot;/> <wsdl:output name=&quot;greetMeSometimeResponse&quot; message=&quot;tns:greetMeSometimeResponse&quot;/> </wsdl:operation> </wsdl:portType> <wsdl:binding name=&quot;GreeterAsync_SOAPBinding&quot; type=&quot;tns:GreeterAsync&quot;> <soap:binding style=&quot;document&quot; transport=&quot;http://schemas.xmlsoap.org/soap/http&quot;/> <wsdl:operation name=&quot;greetMeSometime&quot;> <soap:operation style=&quot;document&quot;/> <wsdl:input> <soap:body use=&quot;literal&quot;/> </wsdl:input> <wsdl:output> <soap:body use=&quot;literal&quot;/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name=&quot;SOAPService&quot;> <wsdl:port name=&quot;SoapPort&quot; binding=&quot;tns:GreeterAsync_SOAPBinding&quot;> <soap:address location=&quot;http://localhost:9000/SoapContext/SoapPort&quot;/> </wsdl:port> </wsdl:service> </wsdl:definitions>
  9. 9. REST <ul><li>REST(Representation State Transfer) </li></ul><ul><li>Dr Roy Fielding </li></ul><ul><li>Resource Based </li></ul><ul><li>Resources with multiple representations </li></ul><ul><li>HTTP(rfc2616) Based </li></ul><ul><li>Stateless </li></ul>
  10. 10. Resource Based GET http://item.taobao.com/auction/ item_detail-0db1-e5ce06f19130167fb925c0d6f219ec0e.htm Client Server
  11. 11. HTTP Based
  12. 12. Resources with multiple representations Client Server GET /persons/jw HTTP/1.1 HOST: www.example.com Accept: Application/xml HTTP/1.1 200 OK Content-Type: text/xml <person> <name>jianzhi wang</name> <age> 23</age> <person> GET /persons/jw HTTP/1.1 HOST: www.example.com Accept: Application/json HTTP/1.1 200 OK Content-Type: text/json {name:jianzhiwang, Age:23}
  13. 14. REST VS WS-* Client Server HTTP SOAP:Action,Parameter,Address,Data,Returns HTTP Head:Action,Prameter,Address,Returns HTTP Body:Data
  14. 15. REST VS WS-*
  15. 16. Q&A

×