際際滷

際際滷Share a Scribd company logo
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
N畛i dung tr狸nh by 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
C叩c 畛ng d畛ng ph但n t叩n Distributed Application D畛 li畛u 畛ng d畛ng ph但n t叩n D畛 li畛u M叩y t鱈nh M叩y t鱈nh
Ki畉n tr炭c h動畛ng d畛ch v畛 Service-Oriented Architecture-SOA Publish Find Bind Service Consumer Service Provider Service Broker
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
Web service l g狸 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
畉c i畛m Kh担ng ph畛 thu畛c vo ng担n ng畛 l畉p tr狸nh 1 Truy c畉p b畉t c畛 畛ng d畛ng no 2 H畛 tr畛 thao t叩c gi畛a c叩c thnh ph畉n kh担ng 畛ng nh畉t 3 Chi ph鱈 ph叩t tri畛n th畉p 4 D畛 b畉o tr狸 5
Ki畉n tr炭c c畛a Web Service Publish Find Bind Internet Web Service Provider UDDI (Web Service Broker) Web Service Consumer
Ki畉n tr炭c c畛a Web Service Any Client SOAP SOAP SOAP UDDI IIS Web Service
Web service provider IIS Y棚u c畉u 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
Web service consumer S畛 d畛ng Web service do WS Provider cung c畉p 畛 x但y d畛ng 畛ng d畛ng
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
M担 h狸nh t動董ng t叩c gi畛a c叩c thnh ph畉n 4 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
N畛n t畉ng c畛a Web Service Web Service XML SOAP HTTP
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 HTTP Request HTTP/1.1  200  OK Content-Type: text/xml; charset=utf-8 Content-Length: 75 <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <stock symbol=&quot;MSFT&quot; Price=&quot;71.50&quot; /> HTTP Response
XML  Extend Markup Language S畛 d畛ng 畛 m担 t畉 Web service interface 1 SOAP Message l m畛t ti li畛u XML 2 S畛 d畛ng 畛 serialize c叩c 畛i t動畛ng thnh m畛t ti li畛u XML (System.Xml.Serialization) 3
SOAP(1) An envelope for handling extensibility and modularity   An encoding mechanism for representing types within an envelope  XML-Based protocol 3 Submitted to W3C 5 Protocol for message-based communication 2 SOAP  HTTP + XML 4 SOAP   Simple Object Access Protocol 1
SOAP (2) POST /WebCalculator/Calculator.asmx HTTP/1.1 Content-Type: text/xml SOAPAction: http://tempuri.org/Add Content-Length: 386 <?xml version=1.0?> <soap:Envelope ...> ... </soap:Envelope> SOAP Request : HTTP POST Request 6
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
SOAP(4) -  Example of a SOAP Request POST /StockQuote HTTP/1.1 Host: www.stockquoteserver.com Content-Type: text/xml;  charset=&quot;utf-8&quot; Content-Length: nnnn SOAPAction: &quot;Some-URI <SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; SOAP-ENV: encodingStyle = &quot;http://schemas.xmlsoap.org/soap/encoding/&quot;> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m=&quot;Some-URI&quot;> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
SOAP(5) -  Example of a SOAP Response HTTP/1.1 200 OK Content-Type: text/xml;  charset=&quot;utf-8&quot; Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV= &quot;http://schemas.xmlsoap.org/soap/envelope/&quot; SOAP-ENV: encodingStyle= &quot;http://schemas.xmlsoap.org/soap/encoding/&quot;/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m=&quot;Some-URI&quot;> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
L畉p tr狸nh Web service b畉ng VS.NET 2003 Web service programming - provider side 1 Web service programming - consumer side 2
L畉p tr狸nh Web service (1)  System System.Data System.Web System.Web.Webservices System.Xml File *.asmx File global.asax File web.config Th動 m畛c Bin Lo畉i Project : ASP.NET Web Service 1 C叩c name space th動畛ng d湛ng 2 C叩c thnh ph畉n 3
L畉p tr狸nh Web service (2) Th棚m ch畛 th畛  [Web Method] Khai b叩o Web service method 4 [WebMethod] public int Sum(int a, int b)  { return a + b; }  V鱈 d畛
L畉p tr狸nh Web service (3) BufferResponse CacheDuration Description EnableSession TransactionOption C叩c thu畛c t鱈nh c畛a  [WebMethod] 5
L畉p tr狸nh Web service (3) [ WebMethod ( BufferResponse=false )] public Transactions GetTransactionHistory() { //implementation code } [ WebMethod  ( Description=This method using for converting ..  )] public double ConvertTemperature(double dFahrenheit) { return ((dFahrenheit - 32) * 5) / 9; } V鱈 d畛
L畉p tr狸nh Web service (4) D湛ng 畛 x叩c 畛nh c畉u tr炭c ti li畛u XML mong mu畛n 畛 bi畛u di畛n 畛i t動畛ng c畛a m畛t l畛p Namespace :  System.Xml.Serialization XmlElement XmlAttribute XmlRoot XML Serialization 5 XmlArrayItem XmlArray
L畉p tr狸nh Web service (5) [ XmlRoot (&quot;account&quot;)] public class Acct { [ XmlElement (&quot;description&quot;)]  public string Description; [ XmlElement (&quot;number&quot;)]  public string Number; [ XmlElement (&quot;type&quot;)]  public string Type; [ XmlElement (&quot;balance&quot;)]  public decimal Balance; [ XmlAttribute (&quot;status&quot;)]  public string Status; } V鱈 d畛 1 <account status=123> <description>Hello</description> <number>10  </number> <type>C</type> <account>
L畉p tr狸nh Web service (6)  [return: XmlArray (&quot; AccountList &quot;)] [return: XmlArrayItem (&quot; Account &quot;)] public  Acct[]  GetAllAccounts()  <AccountList> <account>  <account> <account>  . </account> <AccountList> V鱈 d畛 2
L畉p tr狸nh Web service (7)  [return: XmlArrayItem (ElementName=&quot;savingsAcct&quot;, Type=typeof(SavingsAcct))] [return: XmlArrayItem (ElementName=&quot;creditCardAcct&quot;, Type=typeof(CreditCardAcct))] [WebMethod] public Acct[] GetAllAccounts() { ... <AccountList>  <SavingAcct> </SavingActt>  <CreditCardAcct> </CreditCardActt>  </AccountList> V鱈 d畛 3
L畉p tr狸nh Web service (8) Input and output parameter (in, ref,) Variable length parameter list ( homogeneous, heterogeneous   ) Simple data types Ki畛u d畛 li畛u trong web service method 6 Classes and structures Array, Collections DataSets Complex data type
L畉p tr狸nh Web service  provider side(9)    Ph畉i khai b叩o t動畛ng minh t畉t c畉 c叩c ki畛u d畛 li畛u c坦 th畛 c坦 trong m畉ng S畛 d畛ng : XmlInclude  Name space System.Xml.Serialization Tr動畛ng h畛p l動u 箪 N畉u tham s畛 web service method l 1 m畉ng c叩c 畛i t動畛ng c坦 ki畛u kh担ng r探 rng
L畉p tr狸nh Web service  provider side(10) V鱈 d畛 public class  Acct { public string Description; public string Number; public string Type; public decimal Balance; public string Status; } public class  SavingsAcct  : Acct { public decimal MinimumBalance; } public class  CreditCardAcct  : Acct { public int PayPeriod; } [ WebMethod ] [ XmlInclude (typeof(CreditCardAcct))] [ XmlInclude (typeof(SavingsAcct))] [return: XmlArray (&quot;AccountList&quot;)] [return: XmlArrayItem (&quot;Account&quot;)] public  Acct []  GetAllAccounts () { SavingsAcct a = new SavingsAcct(); CreditCardAcct cc = new CreditCardAcct(); // populate the accounts Acct [] sa = new Acct[2]; sa[0] = a; sa[1] = cc; return sa; }
Tri畛n khai Web service \Web References folder and files .xsd Web.config \bin directory and .dll(s) .xml Global.asax .asmx .vb, .cs Needed Remove Web Service Files .sln, .vbproj, .csproj, .vsdisco, .webinfo .resx T畛 ch辿p c叩c file c畉n thi畉t l棚n Web server 1 S畛 d畛ng Windows Installer Files T畉o 1 web setup project trong VS.NET 2
Web Service Consumer WSDL Documents 1 Proxy class 2 Consuming Web service  in VS.NET 2003  3
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 http://localhost/TestService/service.asmx?wsdl 4
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
S畛 d畛ng Web service trong .NET S畛 d畛ng wsdl.exe S畛 d畛ng VS.Net G畛i b狸nh th動畛ng nh動 c叩c ph動董ng th畛c kh叩c Add Web References  wsdl [ options ] { URL  |  Path } wsdl   http://www.woodgrovebank.com/services/bank.asmx?wsdl T畉o l畛p proxy 畛 giao ti畉p v畛i web service 1 S畛 d畛ng l畛p proxy 畛 g畛i c叩c ph動董ng th畛c c畛a web service 2
WSDL Document
Proxy Class
SOAP Request and Response
HTTP Request and Response
Web service and State Management S畛 d畛ng  畛i t動畛ng  Application  v  Session  畛 qu畉n l箪 tr畉ng th叩i c畛a web service ASP.NET Web service Application    Web Applicaton 1 Web service Application : Stateless 2
畛ng d畛ng c畛a Web Services WS l m畛t t畉p h畛p c叩c ch畛c nng 動畛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 nng 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
Demo
H畛i v 叩p

More Related Content

Viewers also liked (11)

What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
際際滷Share
Masters of 際際滷Share
Masters of 際際滷ShareMasters of 際際滷Share
Masters of 際際滷Share
Kapost
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷shareSTOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
Empowered Presentations
You Suck At PowerPoint!
You Suck At PowerPoint!You Suck At PowerPoint!
You Suck At PowerPoint!
Jesse Desjardins - @jessedee
10 Ways to Win at 際際滷Share SEO & Presentation Optimization
10 Ways to Win at 際際滷Share SEO & Presentation Optimization10 Ways to Win at 際際滷Share SEO & Presentation Optimization
10 Ways to Win at 際際滷Share SEO & Presentation Optimization
Oneupweb
How To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
How To Get More From 際際滷Share - Super-Simple Tips For Content MarketingHow To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
How To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
Content Marketing Institute
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share2015 Upload Campaigns Calendar - 際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share
際際滷Share
What to Upload to 際際滷Share
What to Upload to 際際滷ShareWhat to Upload to 際際滷Share
What to Upload to 際際滷Share
際際滷Share
How to Make Awesome 際際滷Shares: Tips & Tricks
How to Make Awesome 際際滷Shares: Tips & TricksHow to Make Awesome 際際滷Shares: Tips & Tricks
How to Make Awesome 際際滷Shares: Tips & Tricks
際際滷Share
Getting Started With 際際滷Share
Getting Started With 際際滷ShareGetting Started With 際際滷Share
Getting Started With 際際滷Share
際際滷Share
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
際際滷Share
Masters of 際際滷Share
Masters of 際際滷ShareMasters of 際際滷Share
Masters of 際際滷Share
Kapost
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷shareSTOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
STOP! VIEW THIS! 10-Step Checklist When Uploading to 際際滷share
Empowered Presentations
10 Ways to Win at 際際滷Share SEO & Presentation Optimization
10 Ways to Win at 際際滷Share SEO & Presentation Optimization10 Ways to Win at 際際滷Share SEO & Presentation Optimization
10 Ways to Win at 際際滷Share SEO & Presentation Optimization
Oneupweb
How To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
How To Get More From 際際滷Share - Super-Simple Tips For Content MarketingHow To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
How To Get More From 際際滷Share - Super-Simple Tips For Content Marketing
Content Marketing Institute
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
A Guide to 際際滷Share Analytics - Excerpts from Hubspot's Step by Step Guide ...
際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share2015 Upload Campaigns Calendar - 際際滷Share
2015 Upload Campaigns Calendar - 際際滷Share
際際滷Share
What to Upload to 際際滷Share
What to Upload to 際際滷ShareWhat to Upload to 際際滷Share
What to Upload to 際際滷Share
際際滷Share
How to Make Awesome 際際滷Shares: Tips & Tricks
How to Make Awesome 際際滷Shares: Tips & TricksHow to Make Awesome 際際滷Shares: Tips & Tricks
How to Make Awesome 際際滷Shares: Tips & Tricks
際際滷Share
Getting Started With 際際滷Share
Getting Started With 際際滷ShareGetting Started With 際際滷Share
Getting Started With 際際滷Share
際際滷Share

Similar to 際際滷 Web Service (20)

C# co ban 9
C# co ban 9C# co ban 9
C# co ban 9
baotuyet_113
41060-Article Text-130234-1-10-20190706.pdf
41060-Article Text-130234-1-10-20190706.pdf41060-Article Text-130234-1-10-20190706.pdf
41060-Article Text-130234-1-10-20190706.pdf
HiHngLg
Asp
AspAsp
Asp
thinhtu
B tl internet
B tl internetB tl internet
B tl internet
toan
Ung dun web chuong 2
Ung dun web  chuong 2Ung dun web  chuong 2
Ung dun web chuong 2
Giang Nguy畛n
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theoBi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
MasterCode.vn
Computer_Network_Chapter08_ApplicationLaye.pdf
Computer_Network_Chapter08_ApplicationLaye.pdfComputer_Network_Chapter08_ApplicationLaye.pdf
Computer_Network_Chapter08_ApplicationLaye.pdf
12A13TrnMinhHiu
畛Ng d畛ng xml
畛Ng d畛ng xml畛Ng d畛ng xml
畛Ng d畛ng xml
Son Nguyen
Giao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharpGiao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharp
ngohanty13
Introduction Vs2008 Dot Net35
Introduction Vs2008 Dot Net35Introduction Vs2008 Dot Net35
Introduction Vs2008 Dot Net35
TechMaster Vietnam
Web Architecture
Web ArchitectureWeb Architecture
Web Architecture
Hiep Luong
Gi叩o tr狸nh asp.net v畛i c sharp
Gi叩o tr狸nh asp.net v畛i c sharpGi叩o tr狸nh asp.net v畛i c sharp
Gi叩o tr狸nh asp.net v畛i c sharp
Tr畉n Vn S叩ng Tr畉n
Php 01 modau
Php 01 modauPhp 01 modau
Php 01 modau
V動董ng Nhung
Business process excution language
Business process excution languageBusiness process excution language
Business process excution language
Nguyen Tran
Bai44-48.pptx
Bai44-48.pptxBai44-48.pptx
Bai44-48.pptx
BuiManhHung3
Lu畉n vn: K畛 thu畉t i畛u tra ph但n t鱈ch t畉n c担ng web, HAY
Lu畉n vn: K畛 thu畉t i畛u tra ph但n t鱈ch t畉n c担ng web, HAYLu畉n vn: K畛 thu畉t i畛u tra ph但n t鱈ch t畉n c担ng web, HAY
Lu畉n vn: K畛 thu畉t i畛u tra ph但n t鱈ch t畉n c担ng web, HAY
D畛ch V畛 Vi畉t Thu棚 Kh坦a Lu畉n Zalo/Telegram 0917193864
Bai1 gioi thieu_servlet_va_jsp_8952
Bai1 gioi thieu_servlet_va_jsp_8952Bai1 gioi thieu_servlet_va_jsp_8952
Bai1 gioi thieu_servlet_va_jsp_8952
Ham Ch董i
Chuong 1 tongquanve web&amp;htm-lcanban
Chuong 1  tongquanve web&amp;htm-lcanban Chuong 1  tongquanve web&amp;htm-lcanban
Chuong 1 tongquanve web&amp;htm-lcanban
Qu箪 Nguy畛n
41060-Article Text-130234-1-10-20190706.pdf
41060-Article Text-130234-1-10-20190706.pdf41060-Article Text-130234-1-10-20190706.pdf
41060-Article Text-130234-1-10-20190706.pdf
HiHngLg
B tl internet
B tl internetB tl internet
B tl internet
toan
Ung dun web chuong 2
Ung dun web  chuong 2Ung dun web  chuong 2
Ung dun web chuong 2
Giang Nguy畛n
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theoBi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
Bi 1: Lm quen v畛i ASP.NET - Gi叩o tr狸nh FPT - C坦 v鱈 d畛 k竪m theo
MasterCode.vn
Computer_Network_Chapter08_ApplicationLaye.pdf
Computer_Network_Chapter08_ApplicationLaye.pdfComputer_Network_Chapter08_ApplicationLaye.pdf
Computer_Network_Chapter08_ApplicationLaye.pdf
12A13TrnMinhHiu
畛Ng d畛ng xml
畛Ng d畛ng xml畛Ng d畛ng xml
畛Ng d畛ng xml
Son Nguyen
Giao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharpGiao trinh asp.ne_tvoi_csharp
Giao trinh asp.ne_tvoi_csharp
ngohanty13
Introduction Vs2008 Dot Net35
Introduction Vs2008 Dot Net35Introduction Vs2008 Dot Net35
Introduction Vs2008 Dot Net35
TechMaster Vietnam
Web Architecture
Web ArchitectureWeb Architecture
Web Architecture
Hiep Luong
Business process excution language
Business process excution languageBusiness process excution language
Business process excution language
Nguyen Tran
Bai1 gioi thieu_servlet_va_jsp_8952
Bai1 gioi thieu_servlet_va_jsp_8952Bai1 gioi thieu_servlet_va_jsp_8952
Bai1 gioi thieu_servlet_va_jsp_8952
Ham Ch董i
Chuong 1 tongquanve web&amp;htm-lcanban
Chuong 1  tongquanve web&amp;htm-lcanban Chuong 1  tongquanve web&amp;htm-lcanban
Chuong 1 tongquanve web&amp;htm-lcanban
Qu箪 Nguy畛n

際際滷 Web Service

  • 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
  • 2. N畛i dung tr狸nh by 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
  • 3. C叩c 畛ng d畛ng ph但n t叩n Distributed Application D畛 li畛u 畛ng d畛ng ph但n t叩n D畛 li畛u M叩y t鱈nh M叩y t鱈nh
  • 4. Ki畉n tr炭c h動畛ng d畛ch v畛 Service-Oriented Architecture-SOA Publish Find Bind Service Consumer Service Provider Service Broker
  • 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
  • 6. Web service l g狸 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
  • 7. 畉c i畛m Kh担ng ph畛 thu畛c vo ng担n ng畛 l畉p tr狸nh 1 Truy c畉p b畉t c畛 畛ng d畛ng no 2 H畛 tr畛 thao t叩c gi畛a c叩c thnh ph畉n kh担ng 畛ng nh畉t 3 Chi ph鱈 ph叩t tri畛n th畉p 4 D畛 b畉o tr狸 5
  • 8. Ki畉n tr炭c c畛a Web Service Publish Find Bind Internet Web Service Provider UDDI (Web Service Broker) Web Service Consumer
  • 9. Ki畉n tr炭c c畛a Web Service Any Client SOAP SOAP SOAP UDDI IIS Web Service
  • 10. Web service provider IIS Y棚u c畉u 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
  • 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 gi畛a c叩c thnh ph畉n 4 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
  • 14. N畛n t畉ng c畛a Web Service Web Service XML SOAP HTTP
  • 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 HTTP Request HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: 75 <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <stock symbol=&quot;MSFT&quot; Price=&quot;71.50&quot; /> HTTP Response
  • 16. XML Extend Markup Language S畛 d畛ng 畛 m担 t畉 Web service interface 1 SOAP Message l m畛t ti li畛u XML 2 S畛 d畛ng 畛 serialize c叩c 畛i t動畛ng thnh m畛t ti li畛u XML (System.Xml.Serialization) 3
  • 17. SOAP(1) An envelope for handling extensibility and modularity An encoding mechanism for representing types within an envelope XML-Based protocol 3 Submitted to W3C 5 Protocol for message-based communication 2 SOAP HTTP + XML 4 SOAP Simple Object Access Protocol 1
  • 18. SOAP (2) POST /WebCalculator/Calculator.asmx HTTP/1.1 Content-Type: text/xml SOAPAction: http://tempuri.org/Add Content-Length: 386 <?xml version=1.0?> <soap:Envelope ...> ... </soap:Envelope> SOAP Request : HTTP POST Request 6
  • 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
  • 20. SOAP(4) - Example of a SOAP Request POST /StockQuote HTTP/1.1 Host: www.stockquoteserver.com Content-Type: text/xml; charset=&quot;utf-8&quot; Content-Length: nnnn SOAPAction: &quot;Some-URI <SOAP-ENV:Envelope xmlns:SOAP-ENV=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; SOAP-ENV: encodingStyle = &quot;http://schemas.xmlsoap.org/soap/encoding/&quot;> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m=&quot;Some-URI&quot;> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
  • 21. SOAP(5) - Example of a SOAP Response HTTP/1.1 200 OK Content-Type: text/xml; charset=&quot;utf-8&quot; Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV= &quot;http://schemas.xmlsoap.org/soap/envelope/&quot; SOAP-ENV: encodingStyle= &quot;http://schemas.xmlsoap.org/soap/encoding/&quot;/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m=&quot;Some-URI&quot;> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
  • 22. L畉p tr狸nh Web service b畉ng VS.NET 2003 Web service programming - provider side 1 Web service programming - consumer side 2
  • 23. L畉p tr狸nh Web service (1) System System.Data System.Web System.Web.Webservices System.Xml File *.asmx File global.asax File web.config Th動 m畛c Bin Lo畉i Project : ASP.NET Web Service 1 C叩c name space th動畛ng d湛ng 2 C叩c thnh ph畉n 3
  • 24. L畉p tr狸nh Web service (2) Th棚m ch畛 th畛 [Web Method] Khai b叩o Web service method 4 [WebMethod] public int Sum(int a, int b) { return a + b; } V鱈 d畛
  • 25. L畉p tr狸nh Web service (3) BufferResponse CacheDuration Description EnableSession TransactionOption C叩c thu畛c t鱈nh c畛a [WebMethod] 5
  • 26. L畉p tr狸nh Web service (3) [ WebMethod ( BufferResponse=false )] public Transactions GetTransactionHistory() { //implementation code } [ WebMethod ( Description=This method using for converting .. )] public double ConvertTemperature(double dFahrenheit) { return ((dFahrenheit - 32) * 5) / 9; } V鱈 d畛
  • 27. L畉p tr狸nh Web service (4) D湛ng 畛 x叩c 畛nh c畉u tr炭c ti li畛u XML mong mu畛n 畛 bi畛u di畛n 畛i t動畛ng c畛a m畛t l畛p Namespace : System.Xml.Serialization XmlElement XmlAttribute XmlRoot XML Serialization 5 XmlArrayItem XmlArray
  • 28. L畉p tr狸nh Web service (5) [ XmlRoot (&quot;account&quot;)] public class Acct { [ XmlElement (&quot;description&quot;)] public string Description; [ XmlElement (&quot;number&quot;)] public string Number; [ XmlElement (&quot;type&quot;)] public string Type; [ XmlElement (&quot;balance&quot;)] public decimal Balance; [ XmlAttribute (&quot;status&quot;)] public string Status; } V鱈 d畛 1 <account status=123> <description>Hello</description> <number>10 </number> <type>C</type> <account>
  • 29. L畉p tr狸nh Web service (6) [return: XmlArray (&quot; AccountList &quot;)] [return: XmlArrayItem (&quot; Account &quot;)] public Acct[] GetAllAccounts() <AccountList> <account> <account> <account> . </account> <AccountList> V鱈 d畛 2
  • 30. L畉p tr狸nh Web service (7) [return: XmlArrayItem (ElementName=&quot;savingsAcct&quot;, Type=typeof(SavingsAcct))] [return: XmlArrayItem (ElementName=&quot;creditCardAcct&quot;, Type=typeof(CreditCardAcct))] [WebMethod] public Acct[] GetAllAccounts() { ... <AccountList> <SavingAcct> </SavingActt> <CreditCardAcct> </CreditCardActt> </AccountList> V鱈 d畛 3
  • 31. L畉p tr狸nh Web service (8) Input and output parameter (in, ref,) Variable length parameter list ( homogeneous, heterogeneous ) Simple data types Ki畛u d畛 li畛u trong web service method 6 Classes and structures Array, Collections DataSets Complex data type
  • 32. L畉p tr狸nh Web service provider side(9) Ph畉i khai b叩o t動畛ng minh t畉t c畉 c叩c ki畛u d畛 li畛u c坦 th畛 c坦 trong m畉ng S畛 d畛ng : XmlInclude Name space System.Xml.Serialization Tr動畛ng h畛p l動u 箪 N畉u tham s畛 web service method l 1 m畉ng c叩c 畛i t動畛ng c坦 ki畛u kh担ng r探 rng
  • 33. L畉p tr狸nh Web service provider side(10) V鱈 d畛 public class Acct { public string Description; public string Number; public string Type; public decimal Balance; public string Status; } public class SavingsAcct : Acct { public decimal MinimumBalance; } public class CreditCardAcct : Acct { public int PayPeriod; } [ WebMethod ] [ XmlInclude (typeof(CreditCardAcct))] [ XmlInclude (typeof(SavingsAcct))] [return: XmlArray (&quot;AccountList&quot;)] [return: XmlArrayItem (&quot;Account&quot;)] public Acct [] GetAllAccounts () { SavingsAcct a = new SavingsAcct(); CreditCardAcct cc = new CreditCardAcct(); // populate the accounts Acct [] sa = new Acct[2]; sa[0] = a; sa[1] = cc; return sa; }
  • 34. Tri畛n khai Web service \Web References folder and files .xsd Web.config \bin directory and .dll(s) .xml Global.asax .asmx .vb, .cs Needed Remove Web Service Files .sln, .vbproj, .csproj, .vsdisco, .webinfo .resx T畛 ch辿p c叩c file c畉n thi畉t l棚n Web server 1 S畛 d畛ng Windows Installer Files T畉o 1 web setup project trong VS.NET 2
  • 35. Web Service Consumer WSDL Documents 1 Proxy class 2 Consuming Web service in VS.NET 2003 3
  • 36. 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 http://localhost/TestService/service.asmx?wsdl 4
  • 37. 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
  • 38. S畛 d畛ng Web service trong .NET S畛 d畛ng wsdl.exe S畛 d畛ng VS.Net G畛i b狸nh th動畛ng nh動 c叩c ph動董ng th畛c kh叩c Add Web References wsdl [ options ] { URL | Path } wsdl http://www.woodgrovebank.com/services/bank.asmx?wsdl T畉o l畛p proxy 畛 giao ti畉p v畛i web service 1 S畛 d畛ng l畛p proxy 畛 g畛i c叩c ph動董ng th畛c c畛a web service 2
  • 41. SOAP Request and Response
  • 42. HTTP Request and Response
  • 43. Web service and State Management S畛 d畛ng 畛i t動畛ng Application v Session 畛 qu畉n l箪 tr畉ng th叩i c畛a web service ASP.NET Web service Application Web Applicaton 1 Web service Application : Stateless 2
  • 44. 畛ng d畛ng c畛a Web Services WS l m畛t t畉p h畛p c叩c ch畛c nng 動畛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 nng 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
  • 45. Demo