Tải bản đầy đủ (.ppt) (46 trang)

slike bài giảng môn công nghệ web services

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.21 MB, 46 trang )

1
Chuyên đề Thương mại điện tử
Công nghệ Web services
Tháng 11-2006
Khoa Công nghệ thông tin
Bộ môn HTTT
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
2
Nội dung trình bày
Các ứng dụng phân tán
Kiến trúc hướng dịch vụ
Web service
Lập trình Web service
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
3
Các ứng dụng phân tán
Distributed Application
Máy
tính
Máy
tính
Dữ liệu
Ứng dụng
phân tán
Ứng dụng
phân tán
Dữ liệu


11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
4
Kiến trúc hướng dịch vụ
Service-Oriented Architecture-SOA
Service Consumer
Service Consumer
Publish Find
Bind
Service Provider
Service Provider
Service Broker
Service Broker
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
5
Web Service
Web Service là gì ?
Nền tảng của web service
Kiến trúc của web service
Mô hình của ứng dụng với Web service
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
6
Web service là gì
Internet
Internet

Firewall
Firewall
Firewall
Web Service
Web Service
Web Service
Web Service
Web Service
Web Service
Client
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
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
1
Sử dụng để tạo các ứng
dụng phân tán
Sử dụng để tạo các ứng
dụng phân tán
2
2
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT

7
Đặc điểm
Không phụ thuộc vào ngôn ngữ lập trình
Không phụ thuộc vào ngôn ngữ lập trình
1
1
Truy cập bất cứ ứng dụng nào
Truy cập bất cứ ứng dụng nào
2
2
Hỗ trợ thao tác giữa các thành phần không đồng
nhất
Hỗ trợ thao tác giữa các thành phần không đồng
nhất
3
3
Chi phí phát triển thấp
Chi phí phát triển thấp
4
4
Dễ bảo trì
Dễ bảo trì
5
5
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
8
Kiến trúc của Web Service
Publish Find

Bind
Internet
Internet
Web Service
Provider
Web Service
Provider
UDDI (Web
Service Broker)
UDDI (Web
Service Broker)
Web Service
Consumer
Web Service
Consumer
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
9
Kiến trúc của Web Service
UDDI
UDDI
Any Client
Any Client
SOAP SOAP
SOAP
IIS
IIS
Web Service
Web Service

11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
10
Yêu cầu
Yêu cầu
Web service provider
Hỗ trợ 1 protocol listenner
Hỗ trợ 1 protocol listenner
1
1
Có các cơ chế bảo mật
Có các cơ chế bảo mật
2
2
Cung cấp đúng service mà
consumer yêu cầu
Cung cấp đúng service mà
consumer yêu cầu
3
3
Web Server
Web Server
1
1
Cung cấp Web service
Cung cấp Web service
2
2
IIS

IIS
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
11
Web service consumer
Sử dụng Web service do
WS Provider cung cấp để
xây dựng ứng dụng
Sử dụng Web service do
WS Provider cung cấp để
xây dựng ứng dụng
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
12
Web service broker
UDDI
UDDI
Là môi giới giữa consumer và provider
Là môi giới giữa consumer và provider
1
1
Tương tác với provider : để lấy các thông tin về web service
Tương tác với provider : để lấy các thông tin về web service
2
2
Tương tác với consumer :cung cấp cho consumer địa chỉ
các Web service
Tương tác với consumer :cung cấp cho consumer địa chỉ

các Web service
3
3
Sử dụng UDDI registries (Universal Description, Discovery
and Integration)
Sử dụng UDDI registries (Universal Description, Discovery
and Integration)
4
4
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
13
Mô hình tương tác giữa các thành phần
2
2
1
1
5
5
Web service developer builds and deploys a pricing Web service
Web service developer builds and deploys a pricing Web service
1
1
Web service developer registers and categorizes the Web service
Web service developer registers and categorizes the Web service
2
2
Web service consumer queries UDDI for “pricing” services
Web service consumer queries UDDI for “pricing” services

3
3
Web service consumer determines the most appropriate “pricing”
service
Web service consumer determines the most appropriate “pricing”
service
4
4
Web service developer builds a solution that directly
consumes the Web service data
Web service developer builds a solution that directly
consumes the Web service data
5
5
Pricing Web Service
Pricing Web Service
UDDI Services
UDDI Services
3
3
4
4
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
14
Nền tảng của Web Service
Web Service
XMLSOAPHTTP
11/2006Môn: Chuyên đề

TMĐT – Bộ môn
HTTT
15
HTTP – Hyper text transfer protocol
POST /TheStockExchange/Trading/GetStockPrice.asp HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: 11
Symbol=MSFT
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 Request
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 75
<?xml version="1.0" encoding="utf-8"?>
<stock symbol="MSFT" Price="71.50" />
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 75
<?xml version="1.0" encoding="utf-8"?>
<stock symbol="MSFT" Price="71.50" />
HTTP Response
HTTP Response
11/2006Môn: Chuyên đề
TMĐT – Bộ môn

HTTT
16
XML – Extend Markup Language
Sử dụng để mô tả Web service interface
Sử dụng để mô tả Web service interface
1
1
SOAP Message là một tài liệu XML
SOAP Message là một tài liệu XML
2
2
Sử dụng để serialize các đối tượng thành một tài liệu
XML (System.Xml.Serialization)
Sử dụng để serialize các đối tượng thành một tài liệu
XML (System.Xml.Serialization)
3
3
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
17
SOAP(1)
XML-Based protocol
XML-Based protocol
3
3
Submitted to W3C
Submitted to W3C
5
5

Protocol for message-based communication
Protocol for message-based communication
2
2
An envelope for handling extensibility and
modularity
An envelope for handling extensibility and
modularity
An encoding mechanism for representing
types within an envelope
An encoding mechanism for representing
types within an envelope
SOAP ≈ HTTP + XML
SOAP ≈ HTTP + XML
4
4
SOAP – Simple Object Access Protocol
SOAP – Simple Object Access Protocol
1
1
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
18
SOAP (2)
SOAP Request : HTTP POST Request
SOAP Request : HTTP POST Request
6
6
POST /WebCalculator/Calculator.asmx HTTP/1.1

Content-Type: text/xml
SOAPAction: “ />Content-Length: 386
<?xml version=“1.0”?>
<soap:Envelope >

</soap:Envelope>
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
19
SOAP(3) - Message Structure
SOAP Message
SOAP Envelope
SOAP Header
SOAP Body
Message Name & Data
Headers
Headers
XML-encoded SOAP message name
& data
<Body> contains SOAP message name
Individual headers
<Header> encloses headers
<Envelope> encloses payload
Protocol binding headers
The complete SOAP message
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
20

SOAP(4) - Example of a SOAP Request
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml;
charset="utf-8"
Content-Length: nnnn
SOAPAction: "Some-URI“
<SOAP-ENV:Envelope xmlns:SOAP-
ENV=" /> SOAP-ENV: encodingStyle =
" /> <SOAP-ENV:Body>
<m:GetLastTradePrice xmlns:m="Some-URI">
<symbol>DIS</symbol>
</m:GetLastTradePrice>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
21
SOAP(5) - Example of a SOAP Response
HTTP/1.1 200 OK
Content-Type: text/xml;
charset="utf-8"
Content-Length: nnnn
<SOAP-ENV:Envelope
xmlns:SOAP-ENV=
" /> SOAP-ENV: encodingStyle=
" /> <SOAP-ENV:Body>
<m:GetLastTradePriceResponse xmlns:m="Some-URI">
<Price>34.5</Price>

</m:GetLastTradePriceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
22
Lập trình Web service bằng VS.NET 2003
Web service programming - provider side
Web service programming - provider side
1
1
Web service programming - consumer side
Web service programming - consumer side
2
2
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
23
Lập trình Web service (1)
Loại Project : ASP.NET Web Service
Loại Project : ASP.NET Web Service
1
1
Các name space thường dùng
Các name space thường dùng
2
2
System

System.Data
System.Web
System.Web.Webservices
System.Xml
System
System.Data
System.Web
System.Web.Webservices
System.Xml
Các thành phần
Các thành phần
3
3
File *.asmx
File global.asax
File web.config
Thư mục Bin
File *.asmx
File global.asax
File web.config
Thư mục Bin
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
24
Lập trình Web service (2)
Khai báo Web service method
Khai báo Web service method
4
4

Thêm chỉ thị [Web Method]
Thêm chỉ thị [Web Method]
[WebMethod]
public int Sum(int a, int b)
{
return a + b;
}
[WebMethod]
public int Sum(int a, int b)
{
return a + b;
}
Ví dụ
Ví dụ
11/2006Môn: Chuyên đề
TMĐT – Bộ môn
HTTT
25
Lập trình Web service (3)
BufferResponse
BufferResponse
CacheDuration
CacheDuration
Description
Description
EnableSession
EnableSession
TransactionOption
TransactionOption
Các thuộc tính của [WebMethod]

Các thuộc tính của [WebMethod]
5
5

×