Chương 5 Web service

1 Là một tập các phương thức được gọi thực hiện từ xa thông qua một địa chỉ URL 2 Sử dụng để tạo các ứng dụng phân tán

pdf28 trang | Chia sẻ: lylyngoc | Lượt xem: 1648 | Lượt tải: 5download
Bạn đang xem trước 20 trang tài liệu Chương 5 Web service, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Web service Nguyễn Hữu Thể LẬP TRÌNH HỆ THỐNG MẠNG Nội dung Các ứng dụng phân tán 1 Kiến trúc hướng dịch vụ 2 Web service 3 2 Java Web service 4 Tài liệu tham khảo: bài giảng trên tailieu.vn, Internet 3 Các ứng dụng phân tán (Distributed) Máy tính Máy tính Dữ liệu Ứng dụng phân tán Dữ liệu 4 Kiến trúc hướng dịch vụ (SOA) Service Consumer Publish Find Bind Service Provider Service Broker 5 Web service Internet Firewall Firewall Firewall Web Service Web Service Web Service Client Là một tập các phương thức được gọi thực hiện từ xa thông qua một địa chỉ URL 1 Sử dụng để tạo các ứng dụng phân tán 2 6 Đặc điểm Không phụ thuộc vào ngôn ngữ lập trình 1 Truy cập bất cứ ứng dụng nào 2 Hỗ trợ thao tác giữa các thành phần không đồng nhất 3 Chi phí phát triển thấp 4 Dễ bảo trì 5 7 Kiến trúc của Web Service Publish Find Bind Internet Web Service Provider UDDI (Web Service Broker) Web Service Consumer 8 Kiến trúc của Web Service UDDI SOAP SOAP SOAP Client Apache Web Service 9 Kiến trúc phân tầng của Web Service 10 Yêu cầu Web service provider Hỗ trợ 1 protocol listenner 1 Có các cơ chế bảo mật 2 Cung cấp đúng service mà consumer yêu cầu 3 Web Server 1 Cung cấp Web service 2 Apache, Glassfish 11 Web service consumer Sử dụng Web service do WS Provider cung cấp để xây dựng ứng dụng 12 Web service broker UDDI Là môi giới giữa consumer và provider 1 Tương tác với provider : để lấy các thông tin về web service 2 Tương tác với consumer :cung cấp cho consumer địa chỉ các Web service 3 Sử dụng UDDI registries (Universal Description, Discovery and Integration) 4 13 Mô hình tương tác 2 1 5 Web service developer builds and deploys a pricing Web service 1 Web service developer registers and categorizes the Web service 2 Web service consumer queries UDDI for “pricing” services 3 Web service consumer determines the most appropriate “pricing” service 4 Web service developer builds a solution that directly consumes the Web service data 5 Pricing Web Service UDDI Services 3 4 .Net, Java 14 Nền tảng của Web Service Web Service XML SOAP HTTP 15 HTTP POST /TheStockExchange/Trading/GetStockPrice.asp HTTP/1.1 Host: localhost Content-Type: application/x-www-form-urlencoded Content-Length: 11 Symbol=MSFT HTTP Request HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: 75 HTTP Response 16 XML – Extend Markup Language Sử dụng để mô tả Web service interface 1 SOAP Message là một tài liệu XML 2 Sử dụng để serialize các đối tượng thành một tài liệu XML (System.Xml.Serialization) 3 17 SOAP(1) XML-Based protocol 3 Submitted to W3C 5 Protocol for message-based communication 2 An envelope for handling extensibility and modularity An encoding mechanism for representing types within an envelope SOAP ≈ HTTP + XML 4 SOAP – Simple Object Access Protocol 1 18 SOAP (2) SOAP Request : HTTP POST Request 6 POST /WebCalculator/Calculator.asmx HTTP/1.1 Content-Type: text/xml SOAPAction: “” Content-Length: 386 ... 19 SOAP(3) - Message Structure 20 SOAP(4) - Example of a SOAP Request Request <SOAP-ENV:Envelope SOAP-ENV:encodingStyle= "" xmlns:SOAP-ENV="" xmlns:SOAP-ENC= xmlns:xsi="" xmlns:xsd=""> 12 21 SOAP(5) - Example of a SOAP Response <SOAP-ENV:Envelope xmlns:SOAP-ENV= xmlns:xsi= xmlns:xsd=""> <ns1:doubleAnIntegerResponse xmlns:ns1="urn:MySoapServices" SOAP-ENV: encodingStyle= ""> 24 Message response mang thông tin kết quả trả về trong phần body. Kết quả của phép nhân đôi số nguyên 12 là 24. 22 Web Service Consumer WSDL Documents 1 Proxy class 2 Consuming Web service in Java 3 23 WSDL Documents XML schema : Mô tả giao diện của web service 2 Web Service Description Language 1 Sử dụng đề phát sinh proxy class 3 Xem WSDL Document của 1 web service 4 24 WSDL Documents 25 WSDL Documents Hình: WSDL cho phép kết nối lỏng lẻo giữa các dịch vụ 26 Proxy class Được phát sinh từ WSDL Document 2 Được sử đụng để giao tiếp với Web service 3 Proxy : Ủy nhiệm 1 27 Ứng dụng của Web Services WS là một tập hợp các chức năng được thực thi qua môi trường mạng, được các ứng dụng khác sử dụng 1 Một WS có thể kết hợp với các WS khác để đưa ra tính năng cao hơn 2 Mô hình ứng dụng trong tương lai sẽ là sự kết hợp giữa các service 3 … 4