Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 12: Web Services. 12-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Web Services are objects callable across a network.

Similar presentations


Presentation on theme: "Lecture 12: Web Services. 12-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Web Services are objects callable across a network."— Presentation transcript:

1 Lecture 12: Web Services

2 12-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-3 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Part 1 Background…

4 12-4 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 obj Web server Client Web Page Server

5 12-5 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 obj browser Web server HTML Web Page app Server Web Service XML

6 12-6 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (1) Web forms An example of a traditional HTML-based web app: Browser Web server Web Page (1) http://.../WebForm1.aspx (2) HTML WebForm1. (3) view

7 12-7 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-8 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (2) Web services Here's a GUI app built using a calculator web service… GUI.exe Web server Web Service (3) XML 119 (1) XML 20 99 obj int Add(int x, int y) { return x + y; } (2) call (4) view

9 12-9 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Part 2 Demos…

10 12-10 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-11 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Demo #2 TerraServer web service –TerraServer contains global satellite images of Earth's surface –freely-available via this Microsoft-sponsored web service

12 12-12 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Part 3 Consuming a web service…

13 12-13 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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: 1.sign-up for a free Google account 2.create WinForm app as usual 3.set reference to Google web service 4.call Google service like any other object 5.run!

14 12-14 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (1) Getting a Google account It's free! Surf to http://www.google.com/apis/: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 12-15 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (2) Creating WinForm app Create client-side WinForm app as you normally would: WebBrowser controlListBox

16 12-16 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (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.wsdlhttp://api.google.com/GoogleSearch.wsdl

17 12-17 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 Client Web server Web Service WSDL document

18 12-18 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (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 ); } 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 12-19 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (5) Run!

20 12-20 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-21 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 obj Web server obj client app proxy method call HTTP request SOAP msg (XML) stub web service method call WSDL

22 12-22 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Why does Google do this? Amazon? Make $$ –they charge commercial customers per search / sale…

23 12-23 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-24 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Part 4 Creating a web service…

25 12-25 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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 12-26 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (1) Select template Start by creating a project of type “ASP.NET Web Service”

27 12-27 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET (2) Code as usual Web service is just a class with web-callable methods –denoted by WebMethod attribute –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; }. } public class Service1 extends System.Web.Services.WebService { /** @attribute WebMethod() */ public int Add(int x, int y) { return x + y; }. }

28 12-28 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET To use this web service… Give your clients these URLs: –WSDL: http://servername/WebService1/Service1.asmx?wsdlhttp://servername/WebService1/Service1.asmx?wsdl –Web reference:http://servername/WebService1/Service1.asmxhttp://servername/WebService1/Service1.asmx

29 12-29 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET 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


Download ppt "Lecture 12: Web Services. 12-2 MicrosoftIntroducing CS using.NETJ# in Visual Studio.NET Objectives “Web Services are objects callable across a network."

Similar presentations


Ads by Google