1 / 29

Lecture 12: Web Services

Lecture 12: Web Services. Objectives. “Web Services are objects callable across a network. The magic is that web services are platform-independent, for the first time allowing easy creation of heterogeneous systems...” Background Some demos Consuming a web service Creating a web service.

amadeus
Download Presentation

Lecture 12: Web Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 12:Web Services

  2. Objectives “Web Services are objects callable across a network. The magic is that web services are platform-independent, for the first time allowing easy creation of heterogeneous systems...” • Background • Some demos • Consuming a web service • Creating a web service

  3. Part 1 • Background…

  4. Web-based applications • Web server should be viewed as just another application tier • Motivation: • web-based app is now accessible across the internet • web-based app is now accessible from *any* client platform Web server obj obj Client Web Page obj Server

  5. Types of web applications • Two types: • Web forms: web app returns HTML — i.e. data + presentation • Web services: web app returns XML — just the raw data Web server HTML Web Page browser obj obj Web Service XML app obj Server

  6. (1) http://.../WebForm1.aspx (3) view (2) HTML <html> <head> <title>WebForm1</title> </head> <body> <form name="Form1" ...> <scan ...> <input ...> . . . </form> </body> </html> (1) Web forms • An example of a traditional HTML-based web app: Web server Browser Web Page

  7. Problems with form-based web apps • Data intermixed with HTML • what if I just want the data? • Based on user – computer interaction • what if I want to connect computers? • Web services created to solve these problems…

  8. <Add> <x>20</x> <y>99</y> </Add> (1) XML (2) call (3) XML (4) view int Add(int x, int y) { return x + y; } <Add> <result>119</result> </Add> obj (2) Web services • Here's a GUI app built using a calculator web service… Web server GUI.exe Web Service

  9. Part 2 • Demos…

  10. Demo #1 • Amazon web service • Amazon.com makes product info available via a web service • 10% of their business is currently generated this way

  11. Demo #2 • TerraServer web service • TerraServer contains global satellite images of Earth's surface • freely-available via this Microsoft-sponsored web service

  12. Part 3 • Consuming a web service…

  13. Example • Let's create a client that consumes a web service… • Google WebService App: • GUI app that performs internet search using Google! • keep in mind that Google is a web-farm of Linux machines • 5-step process: • sign-up for a free Google account • create WinForm app as usual • set reference to Google web service • call Google service like any other object • run!

  14. (1) Getting a Google account • It's free! • Surf to http://www.google.com/apis/: • follow step 2 to create a Google account (painless) • reply to verification email • you'll receive login key, e.g. "4a8/TvZQFH…"

  15. (2) Creating WinForm app • Create client-side WinForm app as you normally would: ListBox WebBrowser control

  16. (3) Referencing Google web service • Recall that you must reference a component before using it • In the case of web services, set a Web Reference… • for Google, reference http://api.google.com/GoogleSearch.wsdl

  17. What did setting a reference really do? • Setting a web reference requests WSDL doc from service • WSDL = Web Service Description Language • formal description of interface between client & service Web server WSDL document Client Web Service

  18. (4) Calling Google service • Now create Google search object & call! public void cmdSearch_Click(...) { GoogleSearchService google; GoogleSearchResult results; // ask google to search for us... google = new GoogleSearchService(); results = google.doGoogleSearch("4a8/TvZQFHID0WIWnL1CMmMx0sNqhG8H", txtSearch.get_Text(), 0, 10, false, "", false, "", "", ""); // display resulting URLs... for (int i=0; i<results.resultElements.length; i++) lstURLs.get_Items().Add( results.resultElements[i].URL ); }

  19. (5) Run!

  20. What we just did… • Connected two computers across the internet • we're running Windows • Google is running Linux • And we did it via standard OOP • no network programming, no TCP/IP, no XML, no …

  21. obj How does it really work? • Based on RPC (Remote Procedure Call) architecture: • client calls proxy, which builds msg & sends to server • corresponding stub on server receives msg & calls object web service Web server WSDL client app obj obj method call method call stub proxy SOAP msg (XML) HTTP request

  22. Why does Google do this? Amazon? • Make $$ • they charge commercial customers per search / sale…

  23. Why are web services important? • Work on any platform: • Mac OS X, Windows, Linux, ... • Work with most programming languages: • J#, Java, C, C++, VB, C#, … • Work with old, legacy hardware: • new systems can interact with old…

  24. Part 4 • Creating a web service…

  25. Creating a web service • Trivial to do if you're using Visual Studio .NET… • note that IIS must be installed for this to work with VS .NET

  26. (1) Select template • Start by creating a project of type “ASP.NET Web Service”

  27. (2) Code as usual • Web service is just a class with web-callable methods • denoted by WebMethodattribute • code, build, & that's it! public class Service1 extends System.Web.Services.WebService { /** @attribute WebMethod() */ public int Add(int x, int y) { return x + y; } . . . }

  28. To use this web service… • Give your clients these URLs: • WSDL: http://servername/WebService1/Service1.asmx?wsdl • Web reference: http://servername/WebService1/Service1.asmx

  29. Summary • Pretty powerful stuff! • OO construction of heterogeneous systems • Based on lots of technology: • XML for data format • SOAP as communication protocol • WSDL for formal description of web service • ASP.NET, the web component of .NET • proxy-stub distributed design

More Related