Presentation is loading. Please wait.

Presentation is loading. Please wait.

OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls.

Similar presentations


Presentation on theme: "OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls."— Presentation transcript:

1 OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls

2 OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls

3 V1.03 OE-NIK HP Web service A software component that provides services (methods) that is accessible through the Internet –Usually a part of a bigger system –The user (= another application) sees the service as a black-box operation –Can be accessed using well-defined interfaces Advantages –Can be accessible via standardized protocols –The communication formats are based on open standards (XML, JSON) –Independent from OS, programming language, implementation –Easy to describe and publish and use

4 V1.04 OE-NIK HP Service Oriented Architecture Most of the services are built using this pattern Service registry Service userService provider Search Publish Provides Uses

5 OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls

6 V1.0 IP-based alternatives to call a method TCP/UDP (or theoretically even ICMP) –Send and receive a sequence of bytes, must handle the format –Difficult to implement, very fast, almost zero overhead SOAP –Pre-defined SOAP XML formats to define and call the service methods and transmit various data types (array, list, object) –Arbitrary protocol to transmit the XML messages, usually HTTP –Very easy to implement, relatively slow, big overhead –We will use this one REST –Custom JSON format to transmit unique objects (rarely XML) –We rarely need complex parameters, in this case we use HTTP POST to send a JSON object (rarely XML) –Typically we only need the method name and string/int parameters, thus most of the method calls can be represented as HTTP GET requests –The answer is typically JSON (rarely XML) –Easy to implement, medium speed, medium overhead 6 OE-NIK HP

7 V1.0 Discovery The provider can publish the service in a registry The user can search for providers in the registry UDDI: Universal Description, Discovery and Integration –List of services –Possibility to search (service name, company name, location) –Can be private or public registry DISCO –.NET –based service discovery framework, by Microsoft None is used... –Alternative: cloud computing –We do not care about the exact location, API calls will deal with that –„Somewhere” located  the protocol is still a question 7 OE-NIK HP Discovery UDDI, DISCO Description WSDL Message SOAP Transmission HTTP, SMTP, …

8 V1.0 Description The user has to know –The location and the name of the service –The published methods –The message/error types used in the communication –The input parameters –The return types WSDL: Web Services Description Language –A complex XML to describe all of the above 8 OE-NIK HP Discovery UDDI, DISCO Description WSDL Message SOAP Transmission HTTP, SMTP, …

9 V1.0 Message SOAP: Simple Object Access Protocol Just like the WSDL, it is XML data Everything is wrapped into a “SOAP envelope” Send the request-envelope  Receive the response-envelope The creation and the processing of these envelops are completely automatic, the SOAP API libraries hide these There are SOAP API libraries for almost every programming languages! 9 OE-NIK HP Discovery UDDI, DISCO Description WSDL Message SOAP Transmission HTTP, SMTP, …

10 V1.0 Transmission The request-envelope has to be transmitted from the caller to the service provider The service provider decodes the envelope, executes the method, then encodes the return value into the response-envelope The response-envelope has to be transmitted from the service provider to the caller SOAP is NOT dependent on the transmission protocol! Typically (= always) we use HTTP (Hypertext Transfer Protocol) Theoretically it is possible to mix the protocols (send request in FTP, receive in SMTP) 10 OE-NIK HP Discovery UDDI, DISCO Description WSDL Message SOAP Transmission HTTP, SMTP, …

11 V1.0 Service calls in.NET: EVERYTHING is hidden from the programmer! 11 OE-NIK HP SOAP IIS/ASP.NET TCP/IP HTTP TCP/IP SOAP Proxy osztály Physical Link Client application Web Service Logical connection

12 V1.0 Windows Communication Foundation An advanced API to develop and use distributed systems/services Exists since.NET 3.0, hides the physical communication Integrates all the technologies that existed before in.NET –XML-webservices, DCOM,.NET remoting, etc... –This means: SOAP, since the beginning! –Later: REST (REST+Entity Framework: WCF Data Services!) –But NOT the native TCP/UDP communication! 12 OE-NIK HP Client applicationWCF host ProxyWCF service

13 OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls

14 V1.0 General approach The service user application can be any type of application (console, windows, web...) The user application cannot and will not know the implementation details of the service The exposed methods and types are all listed in the WSDL The programming environments are usually capable of generating a proxy class (and message classes) based on the WSDL file Calling a method in the proxy class = SOAP-encode, send, wait, read reply, SOAP-decode The physical implementation of the service is 100% hidden! 14 OE-NIK HP

15 V1.0 Using a SOAP web service in.NET We can create a proxy class by adding a service reference into the project (or manually using the svcutil.exe tool) –Menuitem: Add Service Reference –Type the service address, then click on GO –We can inspect the exposed methods of the service. Then we should specify service name, and then we can click on OK –The proxy class is added to the solution, along with other (parameter & message) classes. They are placed into the namespace projectname.servicename By calling the methods of an instance of the proxy class, we get the result just like with calling regular methods –With SOAP services, the result is usually a string that represents an XML –An XML was encoded in the SOAP envelope XML! The decoding is automatic –We can convert the string result into an Xdocument, then use LINQ to XML 15 OE-NIK HP

16 V1.0 Using a SOAP web service in.NET 16 OE-NIK HP

17 V1.017 OE-NIK HP Exercise 1. Using the web service of the Hungarian National Bank, display the current exchange rates –WSDL downloadable from: http://www.mnb.hu/arfolyamok.asmx (google: mnb asmx) –Old WSDL from the hp webpage –The new WSDL (since 2015/JULY – AUG?) changes almost nothing in the service (fixes one typo in the result XML, but completely screws up the function parameters) Steps: –Add a service reference –Create an instance of the proxy class –Use the GetInfo method to get the list of supported currencies, use the GetCurrentExchangeRates method to get the current exchange rates –Put the result into a DataGrid control

18 V1.018 OE-NIK HP Solution

19 OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls

20 V1.0 Asynchronous calls When generating the proxy class, we can setup to generate threaded (non-blocking) calls –Right click on the service reference, Configure service reference... –Add Service Reference -> Advanced… -> Generate Task-based operations Task-based –An extra method named xxxAsync that returns a Task –We usually use.ContinueWith() Classic APM –An extra method named xxxAsync –An extra event named xxxCompleted –The event will be raised when the operation result arrives –The result is in e.Result 20 OE-NIK HP

21 V1.021 OE-NIK HP Exercise 2. Let the user specify the currencies and dates –Look out for non-existing currencies (ATS now, EUR 20 years ago) –Display the results in the same DataGrid –Using Task-based operations Steps: –Use the GetExchangeRates method –If the two dates are the same => result for that one day

22 V1.0 Solution 22 OE-NIK HP

23

24


Download ppt "OE-NIK HP Advanced Programming Web services Standards and protocols Using web services Using web services with asynchronous calls."

Similar presentations


Ads by Google