Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 UCN / IT - 2012 Distributed Programming Web Services Purpose Examples of Web Services Architecture Web Services in.Net.

Similar presentations


Presentation on theme: "1 UCN / IT - 2012 Distributed Programming Web Services Purpose Examples of Web Services Architecture Web Services in.Net."— Presentation transcript:

1 1 UCN / IT - 2012 Distributed Programming Web Services Purpose Examples of Web Services Architecture Web Services in.Net

2 2 UCN / IT - 2012 Why web services? Applications operates over different platforms –A Java app gets data from a.NET app –A Linux server gets data from an IBM mainframe –A Windows server gets data from a Linux server Application Y Application X

3 3 UCN / IT - 2012 When to use web services? When interoperability between platforms is the important demand. Else: –Proprietary api’s and protocols are more efficient –Proprietary api’s and protocols offers more features –Proprietary api’s and protocols offers better security But web services is… –an easy way to exchange data between two organizations –an easy way to exchange data between a organization’s different systems, i.e. stock, invoicing and dispatching –an easy way to provide a service worldwide

4 4 UCN / IT - 2012 Web service design In the simple form a web service is a tier that wraps a existing tier –meaning a platform neutral interface to existing code: –existing tiers should be used as they are, therefore no recoding DB DTBT Client Server Web server Web Service Web Service Tier ?

5 5 UCN / IT - 2012 Examples of web services What is possible today? There is many different public services: –Amazon.com client (free, but requires signature) –Windows Live search –MapPoint maps & route planner –Google (xml, but not soap) –..... Search for webservices here: http://www.xmethods.net/ Or with your favorite search enginehttp://www.xmethods.net/

6 6 UCN / IT - 2012 Amazon.com web service Amazon.com offers product information via web service Why? –To raise the sale! More than 10% are sold via WS…

7 7 UCN / IT - 2012 MapPoint web service Maps, route planning etc. –Other providers too, i.e. Google Earth, MS Virtual Earth, Yahoo, etc. –Sign up for MapPoint WebService: https://mappoint-css.live.com/mwssignup/

8 8 UCN / IT - 2012 Windows Live web service Execute searches & returns results Example from MSDN

9 9 UCN / IT - 2012 Ways to implement web services Web services can be implemented in many ways. And you can define your own way also. But if you do it in a standardlized way the chance that it will be used is higher and it will properly be easier and cheaper to develop. In these days most web services is based on either SOAP or REST.

10 10 UCN / IT - 2012 SOAP and REST shortly SOAP was one of the first standardlized ways to define webservices. It defines how to serialize data, how to send it, how to find the service, how to scure it etc. As we will see SOAP is very easy to use for developers, because the IDE’s can generate the code for communication But SOAP needs more resources on runtime. Parsing is more complicated and more bytes are sent on the network. REST is more a set of guidelines for making web services. It based on a simple set of operations (usually similar to http) Data is usually serialized to xml or another text format (json) IDE’s cannot (as far as I know) automatically generate code for proxies

11 11 UCN / IT - 2012 Two different ways of thinking SOAP is in many ways similar to RPC. You get a remote object that you can perfom a unlimited set of operations on And, if you are not careful, you forget that is a remote object and handles it as a local object. In SOAP the state is typically kept on the server REST is similar to the classic web protocols (http, ftp,..) Basically you handle data sets in the same way as files with a very limited set of operations. So, in loose terms, you have a data set server instead of a file server. In REST the state is always kept on client. Sum up: –SOAP: Think in terms of objects –REST: Think in terms of ”web”

12 12 UCN / IT - 2012 Demo of two clients that do the same task, but uses web services based on resp. SOAP and REST. After the demo, we’ll look a little more on SOAP. REST is presented more detailed in the next presentation

13 13 UCN / IT - 2012 A little live demo: Valuta conversion There is a SOAP webservice here: –http://www.webservicex.net/CurrencyConvertor.asmxhttp://www.webservicex.net/CurrencyConvertor.asmx

14 14 UCN / IT - 2012 What happened… Accessed systems on other places on the internet Accessed systems running on other platforms Went through a number of firewalls Received non-trivial datatypes … all together programmed in traditional OO. static void Main(string[] args) { WSCurrency.CurrencyConvertor cc = new WSCurrency.CurrencyConvertor(); Console.WriteLine("From EUR to DKK: {0}",cc.ConversionRate(WSCurrency.Currency.EUR,WSCurrency.Currency.DKK)); Console.ReadLine(); } static void Main(string[] args) { WSCurrency.CurrencyConvertor cc = new WSCurrency.CurrencyConvertor(); Console.WriteLine("From EUR to DKK: {0}",cc.ConversionRate(WSCurrency.Currency.EUR,WSCurrency.Currency.DKK)); Console.ReadLine(); }

15 15 UCN / IT - 2012 Basic architekture Standard RPC, but with use of XML & web server: Client Web server obj (2) XML 119 obj = new WebService(); result = obj.Add(20, 99); (1) XML 20 99 int Add(int x, int y) { return x + y; } Service Page

16 16 UCN / IT - 2012 More details… Proxy and stub objects supports RPC Messages in SOAP format –SOAP = Simple Object Access Protocol Web server Client proxy method call HTTP request SOAP msg (XML) Service Page (stub) obj method call

17 17 UCN / IT - 2012 REST based client: Valuta Conversion There is a REST based service here: –http://currencies.apps.grandtrunk.net/http://currencies.apps.grandtrunk.net/ To find the conversion rate DKK to EUR, try the following url in the browser: –http://currencies.apps.grandtrunk.net/getlatest/dkk/eurhttp://currencies.apps.grandtrunk.net/getlatest/dkk/eur Demo: Implement it in C#

18 18 UCN / IT - 2012

19 19 UCN / IT - 2012 What happened Invoked an operation by passing a simple url. Could do in the browser and our own client Got a simple text based value back. It might have been XML that was returned. In that case it would have been necessary to parse the string. But it can implented on any kind of platform: PC’s, phones, tablets, etc..

20 20 UCN / IT - 2012 SOAP, WSDL and UDDI SOAP - Simple Object Access Protocol –Used when the webservice is called WSDL - Web Service Definition Language –Metadata (description) for the webservice UDDI - Universal Description, Discovery and Integration –Used for registration and searching for webservices (Is not widely used, use google or xmethods.net instead)

21 21 UCN / IT - 2012 WSDL We saw that VisualStudio could generate proxy code automatically. It is using the WSDL file. WSDL = Web Service Description Language A formal, platform-neutral definition of a web service –Provided by a web service as a WSDL document –Used by clients to obtain information about a web service Web server Service Page (stub) Service.wsdl obj

22 22 UCN / IT - 2012 Example Get Windows Live’s WSDL dokumentation for the search web service –http://soap.search.msn.com/webservices.asmx?wsdl.http://soap.search.msn.com/webservices.asmx?wsdl

23 23 UCN / IT - 2012 The strength of formal techniques and standardlisation Client-side tools can automatically handle WSDL! Example: –make a “Web Reference” in Visual Studio.NET receive the WSDL and enable IntelliSense, type-check, & proxy generation //Create an instance of the webservice RoutePlanner.Service1 route = new RoutePlanner.Service1(); static List _waypoints = new List (); //Stores the string _country = "Denmark"; //Set country //Lookup for the address in the service string[] fr = route.FindAdressOrLocation(textBox1.Text, _country); //Create an instance of the webservice RoutePlanner.Service1 route = new RoutePlanner.Service1(); static List _waypoints = new List (); //Stores the string _country = "Denmark"; //Set country //Lookup for the address in the service string[] fr = route.FindAdressOrLocation(textBox1.Text, _country);

24 24 UCN / IT - 2012 Beware of the architecture Data-only marshalling! Don't be mistaken: –It looks like objects is MBV (marshal by value) –That is not true! –No code is marshalled, only public data fields –Web service objects are really MBDO (marshal by data only) google = new GoogleSearchService(); result = google.doGoogleSearch("4a8/TvZQFHID0WIWnL1CMmMx0sNqhG8H", txtSearch.Text, 0, 10, false, "", false, "", "", ""); foreach (ResultElement re in result.resultElements)...; google = new GoogleSearchService(); result = google.doGoogleSearch("4a8/TvZQFHID0WIWnL1CMmMx0sNqhG8H", txtSearch.Text, 0, 10, false, "", false, "", "", ""); foreach (ResultElement re in result.resultElements)...;

25 25 UCN / IT - 2012 SOAP SOAP - Simple Object Access Protocol –Used for request and response when the application is runnning. –Contains information about the method, that is called –Parameters for the method –And return values from the method.

26 26 UCN / IT - 2012 SOAP request eur

27 27 UCN / IT - 2012 SOAP Response 0.13437067494390023

28 28 UCN / IT - 2012 WSDL WSDL - Web Service Definition Language Metadata (description) of the webservice –Can be used by developement tools for generation of proxy (stub/skeleton) –Name of the WebService –Parameters – number, type and order –Return type –How to interact with the Web Service using HTTP/SOAP

29 29 UCN / IT - 2012 Make a web service yourself Live demo But in practice, some knowledge of XML is needed

30 30 UCN / IT - 2012 Exercise: Make and deploy a webservice, that returns the server time. There is a weather web service here: http://balder.ucn.dk/weather/Weather.asmx http://balder.ucn.dk/weather/Weather.asmx –Find the weather in Aalborg. First use SearchLocation to find the location id. It returns an array of results. Use the id property Then get a WeatherData object by GetWeather –The service get data from weatherbug.com –You can only use service on Balder for educational use. –The real service on WeatherBug offers more operations, multiple protocols, eg. Rest and soap Homework: –Make one of the “follow-me”- exercises in the folder RouteExercise. The Windows version is a bit easier than the web version.


Download ppt "1 UCN / IT - 2012 Distributed Programming Web Services Purpose Examples of Web Services Architecture Web Services in.Net."

Similar presentations


Ads by Google