Download presentation
Presentation is loading. Please wait.
Published byBarbra Johnston Modified over 9 years ago
1
© Chinese University, CSE Dept. Distributed Systems / 9 - 1 Distributed Systems Topic 7: Web Services and.NET Dr. Michael R. Lyu Computer Science & Engineering Department The Chinese University of Hong Kong
2
© Chinese University, CSE Dept. Distributed Systems / 9 - 2 Part 1: Web Services 1.Introduction 2.Web Services 3.Service descriptions and IDL for web services 4.A directory service for use with web services 5.XML security 6.Coordination of web services 1.Introduction 2.Web Services 3.Service descriptions and IDL for web services 4.A directory service for use with web services 5.XML security 6.Coordination of web services
3
© Chinese University, CSE Dept. Distributed Systems / 9 - 3 1.1 Introduction Simple protocol restricts the potential scope of application. Web services provide an infrastructure for maintaining a richer and more structured form of interoperability between clients and servers. Security Service descriptions (in WSDL) Applications Directory service Web Services XML Choreography SOAP URIs (URLs or URNs)HTTP, SMTP or other transport
4
© Chinese University, CSE Dept. Distributed Systems / 9 - 4 1.2.1 Web Services A web service interface generally consists of a collection of operations that can be used by clients over the Internet. The key characteristic of most web services is they can process XML-formatted SOAP message Properties: –It is accessible over the Web. –It provides an interface that can be called from another program –It is registered and can be located through a Web Service registry. –It communicates using message over standard Web protocols. –It supports loosely coupled connections between system.
5
© Chinese University, CSE Dept. Distributed Systems / 9 - 5 1.2.2 Web Services Loosely-coupled software applications that use open standards to describe an interface for accessing them and a messaging format for communication SOAP/HTTP Database Web Service Web Service Clients
6
© Chinese University, CSE Dept. Distributed Systems / 9 - 6 1.2.3 Characteristic of Web Services Combination of web services –Allows its operations to be combined with those of other services to provide new functionality. hotel booking Travel Agent flight booking hire car booking Service Client flight booking hotel booking hire car booking Example: The ‘travel agent service’ combines other web services
7
© Chinese University, CSE Dept. Distributed Systems / 9 - 7 1.2.3 Characteristic of Web Services Two communication patterns –Processing of a booking takes a long time to complete and could well be supported by an asynchronous exchange of documents –The checking of credit card details and the interactions with the client should be supported by a synchronous request-reply protocol. No particular programming model –They are independent of any particular programming paradigm. –The main differences from the distributed object model are the following: Remote object cannot be instantiated Garbage collection is irrelevant Remote object references are irrelevant
8
© Chinese University, CSE Dept. Distributed Systems / 9 - 8 1.2.3 Characteristic of Web Services Representation of messages –Both SOAP message and the data it carries are represented in XML Services references –Each web service has a URL, which clients use to access the service. Activation services –A web service will be accessed via the computer whose domain name is included in its current URL. Transparency –The details of SOAP and XML are generally hidden by a local API in a programming language. The service description may be used as a basis for automatically generating the necessary marshalling and unmarshalling procedures.
9
© Chinese University, CSE Dept. Distributed Systems / 9 - 9 1.2.4 Web Services Core Technologies Technologies for Web Services –XML –UDDI ( XML Based ) –SOAP ( XML Based ) –WSDL ( XML Based ) Interoperability is the key advantage of Web Services!!!
10
© Chinese University, CSE Dept. Distributed Systems / 9 - 10 1.2.4 The Big Picture An application allows other applications to connect to it over the Web using SOAP This Web Service exposes its methods in a WSDL file The Web Service is published in a UDDI registry to allow other businesses to find it
11
© Chinese University, CSE Dept. Distributed Systems / 9 - 11 1.2.4.1 SOAP Simple Object Access Protocol SOAP is designed to enable both client-server and synchronous interaction over the Web Web services communicate using W3C standard SOAP messages. SOAP formalizes the use of XML as a way to pass data (therefore can be Objects) from one process to another. Originally SOAP was based only on HTTP, but other transport protocols such as TCP are also allowed. <env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope"> Bill Bob Tony
12
© Chinese University, CSE Dept. Distributed Systems / 9 - 12 1.2.4.2 SOAP Messages envelope header body header element body element header element body element
13
© Chinese University, CSE Dept. Distributed Systems / 9 - 13 1.2.4.2 SOAP Messages m:exchange env:envelope xmlns:env =namespace URI for SOAP envelopes m:arg1 env:body xmlns:m = namespace URI of the service description Hello m:arg2 World In this figure and the next, each XML element is represented by a shaded box with its name in italic, followed by any attributes and its content Example of a simple request without headers
14
© Chinese University, CSE Dept. Distributed Systems / 9 - 14 1.2.4.2 SOAP Messages env:envelope xmlns:env = namespace URI for SOAP envelope m:res1 env:body xmlns:m = namespace URI for the service description m:res2 World m:exchangeResponse Hello Example of a reply corresponding to the request in the previous slide
15
© Chinese University, CSE Dept. Distributed Systems / 9 - 15 1.2.4.3 SOAP Headers Intended to be used by intermediaries to add to the service that deals with message carried in the corresponding body. Attribute called role can specify whether every intermediary, none of them, or just the ultimate recipient can process the message.
16
© Chinese University, CSE Dept. Distributed Systems / 9 - 16 1.2.4.4 Transport of SOAP Messages
17
© Chinese University, CSE Dept. Distributed Systems / 9 - 17 1.2.4.4 Transport of SOAP Messages endpoint address action POST /examples/stringer Host: www.cdk4.net Content-Type: application/soap+xml Action: http://www.cdk4.net/examples/stringer#exchange <env:envelope xmlns:env=namespace URI for SOAP envelope > Soap message HTTP header Use of HTTP POST Request in SOAP client-server communication
18
© Chinese University, CSE Dept. Distributed Systems / 9 - 18 1.2.5 A Comparison of Web Services with the Distributed Object Model Remote object references are not very similar to URIs –The URI of a web service can be compared with the remote object reference of a single object. –In distributed object model, objects can create remote objects dynamically and return remote reference to them. Web services model –In the web services models, remote objects cannot be instantiated. Servants –In the distributed object model, the server program is generally modelled as a collection of servants. –Web services do not support servants
19
© Chinese University, CSE Dept. Distributed Systems / 9 - 19 1.2.6 Comparison of Web Services with CORBA Naming issues –In CORBA, each remote object is referenced by means of a name that is managed by an instance of the CORBA naming service. Reference issues –In CORBA, Interoperable Object Reference (IOR) could be used as an Internet-wide object reference in the same way as a URL. But in the web service model, a service is identified by means of a URL. Separation of activation and location –The task of location and activation web services are nearly separated Ease of use –HTTP and XML infrastructure for web services is well-understood and convenient to see and is already installed on all of the most commonly used operation systems Efficiency –CORBA has been designed to be efficient: CORBA CDR is binary, whereas XML is textual.
20
© Chinese University, CSE Dept. Distributed Systems / 9 - 20 1.3 Service Descriptions and IDL for Web Services Interface definitions are needed for clients to communicate with services. Service description specifies two characteristics – how the message are to be communicated and the URI of service. Web Services Description Language (WSDL) abstract concrete howwhere definitions types target namespace interfacebindings services message document stylerequest-reply style
21
© Chinese University, CSE Dept. Distributed Systems / 9 - 21 WSDL has a well-defined XML vocabulary to answer the following questions regarding the web service involved: What does the service do? –Both in machine and human-readable forms What language does the service speak? –The format/data structure of the message exchanged How does the client talk to the service? –HTTP/SMTP/FTP Where is the location of the web service? –The access point (URL) 1.3 WSDL
22
© Chinese University, CSE Dept. Distributed Systems / 9 - 22 1.3 WSDL – Messages or Operations Need a common idea about the message to be exchanged message name = " ShapeList_newShape " type = " tns:GraphicalObject " part name="GraphicalObject_1" tns : target namespace xsd : XML schema definitions message name = " ShapeList_newShapeResponse " part name= " result " type = " xsd:int " WSDL request and reply messages for the newShape operation
23
© Chinese University, CSE Dept. Distributed Systems / 9 - 23 1.3 WSDL – Interface Name In-Out In-Only Robust In-Only Out-In Out-Only Robust Out-Only ClientServerDelivery Fault message RequestReply may replaceReply Request no fault message Requestguaranteed may be sent ReplyRequest may replaceReply Request no fault message Requestguaranteedmay send fault Messages sent by Message exchange patterns for WSDL operations
24
© Chinese University, CSE Dept. Distributed Systems / 9 - 24 1.3 WSDL – Inheritance Can extend one or more other WSDL interface Recursive definition of interface is not allowed: If interface B extends interface A, then interface A cannot extend interface B
25
© Chinese University, CSE Dept. Distributed Systems / 9 - 25 1.3 WSDL – Concrete Part Binding (choice of protocols) and Service (choice of endpoint or sever address): soap:binding transport = URI binding style= " rpc " endpoint service name = binding = " tns:ShapeListBinding " soap:address location = service URI name = " MyShapeListService " name = " ShapeListPort " for schemas for soap/http the service URI is: operation soap:operation soapAction " ShapeListBinding " " tns:ShapeList " type = name= " newShape " input soap:body encoding, namespace soap:body encoding, namespace output “ http://localhost:8080/ShapeList-jaxrpc/ShapeList”
26
© Chinese University, CSE Dept. Distributed Systems / 9 - 26 1.3 WSDL Concrete Part: Binding and Service Binding: –The binding section in WSDL specifies which message formats and form of external data representation Service: –Each service element specifies the endpoints where an instance of the service may be contacted. Documentation: –Both human and machine readable information may be inserted in a documentation element at most points within a WSDL document. WSDL use: –Complete WSDL can be accessed via their URIs by clients and servers, either directly or indirectly via a directory services as UDDI.
27
© Chinese University, CSE Dept. Distributed Systems / 9 - 27 1.3 Generating WSDL Code Web Services generate WSDL using introspection and clients grab the WSDL file and generate code to call the service C# Implementation Example: public class MathService : WebService { [WebMethod] public float Add(float a, float b) { return a + b; }
28
© Chinese University, CSE Dept. Distributed Systems / 9 - 28 1.3 WSDL <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://tempuri.org/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns="http://schemas.xmlsoap.org/wsdl/"> …
29
© Chinese University, CSE Dept. Distributed Systems / 9 - 29 1.4 A Directory Service for Use with Web Services UDDI – Universal Description, Discovery, and Integration Service Data structures allow human-readable information access tModel businessServices tModel businessEntity information about the publisher tModel businessServices human readable service descriptions key URL businessServices information about a family of services human readable service interfaces bindingTemplate information about the key service interfaces
30
© Chinese University, CSE Dept. Distributed Systems / 9 - 30 1.4 A Directory Service for Use with Web Services Lookup –UDDI provides an API for looking up services based on 2 sets of query operation: get_xxx, find_xxx. –UDDI provides a notify/subscribe interface Publication –UDDI provides an interface for publishing and updating information about web services. Registries –UDDI service is based on replicated data stored in registries
31
© Chinese University, CSE Dept. Distributed Systems / 9 - 31 1.4 UDDI UDDI defines a way to publish and discover information about Web services
32
© Chinese University, CSE Dept. Distributed Systems / 9 - 32 1.5 XML Security Related to W3C designs for signing, key management and encryption. WS-security is another approach to security. Basic requirement: –To be able to encrypt either an entire document or just some selected parts of it. –To be able to sign either an entire document or just some selected parts of it
33
© Chinese University, CSE Dept. Distributed Systems / 9 - 33 1.5 XML Security Additional basic requirements –To add to a document that is already signed and to sign the result –To add to a document that already contains encrypted sections and to encrypt part of the new version, possibly including some of the already encrypted section. –To authorize various different users to view different parts of a document.
34
© Chinese University, CSE Dept. Distributed Systems / 9 - 34 1.6 Coordination of Web Services SOAP infrastructure supports single request-response interactions between clients and web services. Web service choreography allows a set of interactions between pairs of web services working together in a joint task. –To generated code outline for new service that wants to participate –As a basis for generating test messages for a new service –To promote a common understanding of the collaboration –To analyze the collaboration, for example to identify possible deadlock situations.
35
© Chinese University, CSE Dept. Distributed Systems / 9 - 35 1.6 Global XML Web Services Architecture SOAP HTTP/SMTPXMLTCP/IP Directory Inspection Building Block Modules Building Block Modules Inter Application Protocols Referral Routing Security License EventingTransactions Reliable Messaging The Internet Description … …
36
© Chinese University, CSE Dept. Distributed Systems / 9 - 36 1.7 Quality-of-Service (QoS) QoS representing non-functional performance of Web services –How will I know the web service will meet my performance requirements such as 2 ms response time? –Will the web service be reliable for my mission-critical system’s implementation? Domain-independent –Throughput, capacity, latency, response time (duration), availability, reliability, reputation, execution cost (price) Domain-dependent –Currency converters: accuracy –Hotel booking: prices, number of the rooms, availability rate
37
© Chinese University, CSE Dept. Distributed Systems / 9 - 37 1.8 Amazon Web Services
38
© Chinese University, CSE Dept. Distributed Systems / 9 - 38 1.9 Resources of Web Services Web service searching engine –http://webservices.seekda.comhttp://webservices.seekda.com Web sites –http://www.webservicex.nethttp://www.webservicex.net –http://www.xmethods.comhttp://www.xmethods.com –http://www.webservicelist.comhttp://www.webservicelist.com Web services of well know companies: –Amazon, Google, Yahoo, YouTube, Facebook, etc.
39
© Chinese University, CSE Dept. Distributed Systems / 9 - 39 Part 2: RESTful Web Services
40
© Chinese University, CSE Dept. Distributed Systems / 9 - 40 REST Concept REST is between ResourceR epresentational S tate T ransfer between Resource A style of software architecture A Virtual state-machine A network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.
41
© Chinese University, CSE Dept. Distributed Systems / 9 - 41 Why REST? Simple, both conceptually and programmatically Simpler and cleaner than SOAP
42
© Chinese University, CSE Dept. Distributed Systems / 9 - 42 SOAP Example POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn IBM
43
© Chinese University, CSE Dept. Distributed Systems / 9 - 43 REST Example GET /stock/IBM HTTP/1.1 Host: www.example.org Accept: application/xml
44
© Chinese University, CSE Dept. Distributed Systems / 9 - 44 SOAP Example 2 POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn IBM 50
45
© Chinese University, CSE Dept. Distributed Systems / 9 - 45 REST Example 2 POST /order HTTP/1.1 Host: www.example.org Content-Type: application/xml; charset=utf-8 IBM 50
46
© Chinese University, CSE Dept. Distributed Systems / 9 - 46 Client-Server Separation principle Components Independent Stateless Session state on the client Visibility, reliability and scalability Trade off (network performance, etc.) Cacheable A response can be cacheable Efficiency but reduce reliability Layered system System scalability Code on demand (optional) Extension after deployment Uniform Interface Simple REST Constraints
47
© Chinese University, CSE Dept. Distributed Systems / 9 - 47 Resources and Resource Identifiers Uniform Interface (GET, PUT, POST, DELETE) Resource Oriented Simple and simple is beautiful REST Data Elements HTTPMethodCRUD Desc. POSTCREATECreate- GETRETRIEVERetrieveSafe,Idempotent,Cacheable PUTUPDATEUpdateIdempotent DELETE DeleteIdempotent
48
© Chinese University, CSE Dept. Distributed Systems / 9 - 48 SOAP Simple Object Access Protocol RPC protocol that go through firewalls Communication protocol between applications A format for sending messages REST V.S. SOAP
49
© Chinese University, CSE Dept. Distributed Systems / 9 - 49 REST “The Web is the universe of globally accessible information” Resource oriented User-driven interactions via forms Few operations (generic interface) on many resources URI: Consistent naming mechanism for resources Focus on scalability and performance of large scale distributed hypermedia systems SOAP “The Web is the universal transport for messages” Activity/Service oriented Orchestrated reliable event flows Many operations (service interface) on few resources Lack of standard naming mechanism Focus on design of integrated (distributed) applications REST V.S. SOAP
50
© Chinese University, CSE Dept. Distributed Systems / 9 - 50 Two of most common styles of use of Web Services Service-oriented architecture “Message oriented” (SOAP) Contract provided by WSDL REST Focus on interacting with stateful resources, rather than messages or operations. REST V.S. SOA
51
© Chinese University, CSE Dept. Distributed Systems / 9 - 51 REST V.S. SOA Correlation REST is an architectural style that inherently helps to attain some of the basic SOA principles. SOA principles Standardized Service Contracts Service Loose Coupling Service Abstraction Service Reusability Service Autonomy Service Statelessness Service Discoverability Service Composability REST principles Unique identifiability of the resources through URIs Uniform interface to access the resources Navigability of the resource representations through hypermedia Statelessness
52
© Chinese University, CSE Dept. Distributed Systems / 9 - 52 Part 3:.NET
53
© Chinese University, CSE Dept. Distributed Systems / 9 - 53 Tools for Building Web Services Visual Studio.NET – developed by Microsoft –http://www.microsoft.com/net/http://www.microsoft.com/net/ WebSphere – developed by IBM –http://www-306.ibm.com/software/websphere/http://www-306.ibm.com/software/websphere/ Eclipse and Axis2 – open source tools –http://www.eclipse.org/http://www.eclipse.org –http://ws.apache.org/axis2/http://ws.apache.org/axis2/ Mono – an open-source project providing the necessary software to develop and run.NET client and server applications –http://www.mono-project.com/Web_Serviceshttp://www.mono-project.com/Web_Services
54
© Chinese University, CSE Dept. Distributed Systems / 9 - 54 What Is.NET Software as a service (SaaS) Accessible over many devices and operating systems Language Neutral Component Based Advantages of.NET –A language neutral environment for writing programs that can easily interoperate –Programs are not created with a target OS/device in mind, but with the target of.NET
55
© Chinese University, CSE Dept. Distributed Systems / 9 - 55 A Breakdown of.NET.NET Framework –Compilation Process –Major Components of the.NET framework The Internet with.NET –Building Web Services –Consuming Web Services –ASP.NET and XML Web Services
56
© Chinese University, CSE Dept. Distributed Systems / 9 - 56 What Is the.NET Framework The.NET framework is the infrastructure for the overall.NET Platform. Major Components of the framework –Common Language Runtime (CLR) –Base Class Library –Common Type System (CTS) –Common Language Specification (CLS)
57
© Chinese University, CSE Dept. Distributed Systems / 9 - 57.NET Framework StructureWin32 MSMQ(MessageQueuing)COM+ (Transactions, Partitions, Object Pooling, …) IISWMI Common Language Runtime Base Class Library ADO.NET: Data and XML Web Services/WebForms WindowsForms ASP.NET … Visual Studio.NET Common Language Specification (CLS) VBC++C#JScript 30+ Languages
58
© Chinese University, CSE Dept. Distributed Systems / 9 - 58 Web Services in.NET Enables disparate systems to exchange data using internet standards (http, xml, soap) Pieces of program logic that are exposed publicly (UDDI) Black boxes of program logic that abstract the functionality away from consuming application Consuming application needs only to know how to invoke the web service and what to expect in return
59
© Chinese University, CSE Dept. Distributed Systems / 9 - 59 Web Services with.NET Data Tier Business Tier Components Web Services XML Presentation Tier App.Exe Windows Form IE / IIS Web Form
60
© Chinese University, CSE Dept. Distributed Systems / 9 - 60 Web Services with.NET
61
© Chinese University, CSE Dept. Distributed Systems / 9 - 61 Three Steps to Consuming Web Services Discovering XML Web Service –May use the Universal Description, Discovery, and Integration service (UDDI) –Result of discovery is the URL to the Web Service Description (WSDL) document Creating a Proxy –Proxy is a class on the local server which exposes the same interfaces as the XML Web Services –Handles calls to Web Service to invoke the specified Web method. –Using.NET framework we can use the WSDL.exe utility which automatically generates a proxy class for the service Creating an instance and invoking –Once we have proxy class, we can create an instance and invoke any of it’s methods –When method invoked, proxy calls out to XML web service and invokes same method –Proxy then exposes output to original caller, as if method were invoked locally
62
© Chinese University, CSE Dept. Distributed Systems / 9 - 62 Example: Consuming XML Web Services 1.The consumer finds an available XML Web Service either in the UDDI registry, or directly from the provider (not shown). 2.The consumer makes a request to the provider for the WSDL document. 3.The provider returns the XML-based WSDL document. 4.The consumer makes a request to the XML Web Service in the WSDL document, passing in any required arguments as defined in the WSDL. 5.The provider processes the request, performing any functions necessary to complete the request, and returns the result to the consumer as either an XML document, or a SOAP message.
63
© Chinese University, CSE Dept. Distributed Systems / 9 - 63 Building Web Services Must create a.asmx file which defines the class and methods of XML Web Service.asmx file does not define user interface Must declare classes as WebService, and methods as WebMethod
64
© Chinese University, CSE Dept. Distributed Systems / 9 - 64 Summary XML Web Service is a new solution towards distributed component interoperability. The Microsoft.NET framework is a new platform environment integrated with Windows OS. This is Microsoft’s platform for enabling XML Web Services. Read Textbook Chapter 9.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.