Web Services Definition q Many definitions technologies that

  • Slides: 48
Download presentation
Web Services

Web Services

Definition q Many definitions § “…technologies that allow for making connections” § “a software

Definition q Many definitions § “…technologies that allow for making connections” § “a software system designed to support interoperable m 2 m interaction over the network” § “. . a service offered by an electronic device to another electronic device, communicating with each other via WWW” q Web services may use SOAP protocol over http (or ftp, smtp, . . ) for their communication q http is utilized for m 2 m communication and for transferring information in XML or JSON q Has an interface described in WSDL or REST (WADL, RAML, OAS/Open. Api) machine-readable format 3/12/2021 Web Services 2

Service q. A function that is well defined, self contained, does not depend on

Service q. A function that is well defined, self contained, does not depend on the context or state of other services, can be accessed remotely and updated independently q. Services carry out a function, such as producing data, validating a customer, or retrieve a credit card statement q. Web services: connection technology of SOA q. Most APIs in cloud computing are implemented as SOAP or RESTful Web services 3/12/2021 Web Services 3

Web Services vs Websites q. A Web site is typically intended for human consumption

Web Services vs Websites q. A Web site is typically intended for human consumption (human-to-computer interaction), whereas web services are typically intended for computer-to-computer interaction q. A Web service may have GUI or API, a Web site may implement Web Services in the background § Paypal has both GUI and implements web services (e. g. for payments, use management etc. ) 3/12/2021 http: //tutorials. jenkov. com/web-services/ 4

A Service example q Basic service oriented architecture: The service provider returns a response

A Service example q Basic service oriented architecture: The service provider returns a response message to the service consumer (client) q Simple data, message passing q The request and subsequent response connections are defined in some way that is understandable to both the service consumer and service provider 3/12/2021 Web Services 5

Service Oriented Architecture (SOA) q Architecture based on services: All functional components of a

Service Oriented Architecture (SOA) q Architecture based on services: All functional components of a system are viewed as services that communicate with each other through well defined interfaces by message passing q One of the keys to SOA architecture is that interactions occur with loosely coupled services that operate independently q SOA architecture allows for service reuse, making it unnecessary to start from scratch when developing an application or when upgrades and other modifications are needed q This is a benefit to businesses that seek ways to save time and money 3/12/2021 Web Services 6

SOA Patterns q. A SOA building block can play one of the following roles

SOA Patterns q. A SOA building block can play one of the following roles § Service broker: Also known as service registry; Its main functionality is to make the information regarding the web services available to any potential requester (public or private brokers) § Service consumer: It locates entries in the broker registry (using find operations), binds to the service provider, invokes its web service § Service provider: It creates a web service and provides its information to the service registry, provides responses to consumers 3/12/2021 Web Services 7

Service Registry (Broker) q UDDI is a registry for the discovery of services described

Service Registry (Broker) q UDDI is a registry for the discovery of services described by WSDL q WSDL is an XML-based description language for services q SOAP is the protocol for exchanging information in the communication of Web services over http q UDDI, WSDL, SOAP, XML are platform and language independent q Procedure: § A service provider describes its services using WSDL § Publishes its service in the registry (UDDI) § A service consumer issues queries to the registry to locate a service § The registry returns WSDL description § The consumer knows how to use and communicate with the service § The consumer uses SOAP to send a request to the service provider § The provider returns a response to the service consumer 3/12/2021 Web Services 8

Web Services basic architecture 3/12/2021 Web Services 9

Web Services basic architecture 3/12/2021 Web Services 9

SOA Principles 1/2 q Standardized service contract: services adhere to the same design principles,

SOA Principles 1/2 q Standardized service contract: services adhere to the same design principles, usually expressed as WSDL, REST, … documents, XML schema q Service reference autonomy (loose coupling): services are independent and control the functionality they provide on their own q Service location transparency (loose coupling): services can be called from anywhere q Service abstraction: services as black boxes (inner logic is hidden) q Service granularity: services have adequate size and scope (provide functionality relevant to request) 3/12/2021 Web Services 10

SOA Principles 2/2 q Service composability: can be used to compose other services q

SOA Principles 2/2 q Service composability: can be used to compose other services q Service discovery: come with communicative metadata by which they can be discovered and interpreted q Service re-usability: promote re-use of code q Service encapsulation: may get encapsulated or become part of a SOA q Service statelessness: services are stateless and simply return the requested value or an exception, each request is unrelated to any previous request 3/12/2021 Web Services 11

SOA and Cloud Computing q Complementary technologies q While SOA exhibited varying success in

SOA and Cloud Computing q Complementary technologies q While SOA exhibited varying success in the past, the movement to cloud computing provides some renewed value to SOA q Clouds are typically API or service-driven, and therefore service-oriented q As cloud computing becomes more popular, more enterprises will use SOA, which includes the use of service directories, orchestration, and other technologies related to SOA q FIWARE, ORACLE provide collections of RESTful services (IDM, CB) 3/12/2021 Web Services 12

WSDL q. XML format that describe services as a set of service end-points for

WSDL q. XML format that describe services as a set of service end-points for data/message exchange q. Service End-Point: Describes a service and how it is bound to specific IP addresses / interface § declares all abstract methods that are exposed to the client 3/12/2021 Web Services 13

WSDL Documents (XML) q. Specifies location and methods of service using § <types> XML

WSDL Documents (XML) q. Specifies location and methods of service using § <types> XML data types used by the service § <message> data elements for each operation § <port. Type> operations that can be performed with the messages involved § <binding> defines protocol, operations and data format for each port type § Port: end-point as combination of binding + IP § Service: a collection of end-points 3/12/2021 Web Services 14

Structure of WSDL document 3/12/2021 Web Services 15

Structure of WSDL document 3/12/2021 Web Services 15

WSDL Example 1/2 3/12/2021 Web Services 16

WSDL Example 1/2 3/12/2021 Web Services 16

WSDL Name Spaces qxmlns: set default name spaces for the entity being described qtarget.

WSDL Name Spaces qxmlns: set default name spaces for the entity being described qtarget. Name. Space: the name space for your web service (points to the WSDL of the service) qtns: same URI as target. Name. Space 3/12/2021 Web Services 17

WSDL Example 2/2 3/12/2021 Web Services 18

WSDL Example 2/2 3/12/2021 Web Services 18

Example Explanation 1/2 q Definitions: “Hello. Service” q Type: Using built-in data types and

Example Explanation 1/2 q Definitions: “Hello. Service” q Type: Using built-in data types and data types defined in XML schema q Message: § “Say. Hello. Request”: “first. Name” parameter § “Say. Hello. Response”: “greeting” return value q Port Type: “say. Hello” operation that consists of a request and a response service q Binding: Direction to use the SOAP http protocol q Service: operations available at http: //www. examples. com/Say. Hello/ 3/12/2021 https: //www. ibm. com/support/knowledgecenter/en/SSB 27 H_6. 2. 0/fa 2 ws_ovw_soap_syntax_lit. html 19

Encoding. Style Attribute q Can be used to indicate the encoding style used for

Encoding. Style Attribute q Can be used to indicate the encoding style used for the header entries, either simple or compound data types § Compound types: structure array, string, enumeration q Indicate the serialization rules used in a SOAP message q The attribute value is an ordered list of one or more URIs identifying the serialization rule or rules that can be used to de/serialize the SOAP message q Examples of values are: § "http: //schemas. xmlsoap. org/soap/encoding/" § "http: //my. host/encoding/restricted http: //my. host/enco ding/” 3/12/2021 https: //www. w 3. org/TR/2000/NOTE-SOAP 20000508/#_Toc 478383512 Services 20

XML Serialization q Serialization is the process of converting an object into a form

XML Serialization q Serialization is the process of converting an object into a form that can be transported q Serialize an object and transport it over the internet using http between a client and a serve q Deserialization reconstructs the object from the stream q XML serialization serializes only the public fields and property values of an object into an XML stream q XML serialization does not include type information § Eg. , a Book object that exists in the Library namespace, there is no guarantee that it is deserialized into an object of the same type. 3/12/2021 Web Services 21

SOAP q Simple Object Access Protocol (SOAP): a protocol based on XML for exchanging

SOAP q Simple Object Access Protocol (SOAP): a protocol based on XML for exchanging information among computers q Specifies how to communicate / pass messages using http q Initially used for remote procedure calls q Similar to CORBA, DCOM, Java RMI but SOAP messages are written in XML (language / platform independent) § Communication protocol for internet § Extends http for XML messaging specifying what information is sent § Provides data transport for Web services § Can also used for document exchange § Language / platform independent § Can be used with Java, PHP, … 3/12/2021 Web Services 22

SOAP Message q XML document with elements § Envelope: defines start/end of message, identifies

SOAP Message q XML document with elements § Envelope: defines start/end of message, identifies the XML document as SOAP message § Header: attributes for processing the message § Body: message that contains call/response information § Fault: information about errors that occur while processing the message q All elements are declared in the default namespace for the SOAP envelope http: //www. w 3. org/2003/05/soapenvelope/ q Default name space for SOAP data http: //www. w 3. org/2003/05/soap-encoding 3/12/2021 Web Services 23

SOAP Message Structure q Provides an “envelope” for sending Web service messages over internet

SOAP Message Structure q Provides an “envelope” for sending Web service messages over internet (typically http) q Envelope parts: q. Optional header q. Body (message) 3/12/2021 Web Services 24

SOAP Message Structure XML namespaces disambiguate SOAP identifiers from application specific identifiers. 3/12/2021 Web

SOAP Message Structure XML namespaces disambiguate SOAP identifiers from application specific identifiers. 3/12/2021 Web Services 25

SOAP Header Element q. Application specific information § must. Understand Attribute: indicates whether the

SOAP Header Element q. Application specific information § must. Understand Attribute: indicates whether the header is mandatory for the recipient ü processsoap: must. Understand="0|1” § Actor Attribute: address of recipient of the Header soap: actor='http: //example. org/Nodes/Fireball/XL 5'> § Encoding. Style Attribute: define the data types and serialization rules ü soap: encoding. Style="http: //www. w 3. org/2003/05/so ap-encoding"> 3/12/2021 Web Services 26

SOAP Fault Element q Indicates error messages (optional) and has subelements § <faultcode> identifies

SOAP Fault Element q Indicates error messages (optional) and has subelements § <faultcode> identifies the fault ü Version. Missmatch: invalid namespace found ü Must. Understand: an element with “ 1” attributed was not understood ü Client: message incorrectly formed or contained fault information ü Server: problem with server so the message could not proceed § <faultstring> human readable information § <faultactor> who caused the fault § <detail> fault specific information 3/12/2021 Web Services 27

SOAP Request for Price of Apples q m: Get. Price, m: Price are application

SOAP Request for Price of Apples q m: Get. Price, m: Price are application specific 3/12/2021 Web Services 28

SOAP Response 3/12/2021 Web Services 29

SOAP Response 3/12/2021 Web Services 29

SOAP example: Get. Quotation request 3/12/2021 Web Services 30

SOAP example: Get. Quotation request 3/12/2021 Web Services 30

SOAP example: Quotation response 3/12/2021 Web Services 31

SOAP example: Quotation response 3/12/2021 Web Services 31

SOAP example: Get. Stock. Price request 3/12/2021 Web Services 32

SOAP example: Get. Stock. Price request 3/12/2021 Web Services 32

SOAP example: Get. Stock. Price response 3/12/2021 Web Services 33

SOAP example: Get. Stock. Price response 3/12/2021 Web Services 33

Representation State Transfer (REST) q. REST is a lightweight alternative to SOAP Like Web

Representation State Transfer (REST) q. REST is a lightweight alternative to SOAP Like Web services § § 3/12/2021 Platform independent Runs on http Language independent Can be used with most programming environments like C#, Java. Script, Perl, PHP, Python … Web Services 34

Restful Web Services q. In REST everything is a resource which is identified by

Restful Web Services q. In REST everything is a resource which is identified by its URI q. A URI is of following format § <protocol>: //<service-name>/<Resource. Type>/<Resource. ID> § http: //localhost: 8080/User. Management/rest/User. Service/users q. A REST server provides access to resources and REST client accesses and presents resources q. A RESTful web service usually defines a URI, provides resource representation such as JSON and a set of http methods 3/12/2021 Web Services 35

How Simple is REST ? q SOAP to query a phone book for the

How Simple is REST ? q SOAP to query a phone book for the details of a given user q REST (no “body”, its just a URL sent to server using an http POST request) q Can handle requests with multiple parameters 3/12/2021 Web Services 36

Definition of REST 1/2 q Client-Server: Client and server application can evolve separately without

Definition of REST 1/2 q Client-Server: Client and server application can evolve separately without any dependency on each other (also SOA) q Stateless: The service doesn't store information from previous requests (also SOA) § A request from a client contains the necessary information to interact with the service q Cacheable: Response messages are labeled as cacheable or non-cacheable § If cacheable, a client is given the right to cache and reuse response data for later, equivalent requests § Performance improvement: reduces the number of requests to server as clients may instantly reuse existing 3/12/2021 information without the need to send a new request Web Services 37

Definition of REST 2/2 q Uniform Interface (HATEOAS): A client needs min or no

Definition of REST 2/2 q Uniform Interface (HATEOAS): A client needs min or no prior information on how to interact with server § Server's responses include hyperlinks that a client can use to discover all the available actions and resources it needs § Simplifies the service architecture § Every component of the service can evolve independently q Layered System: Architecture is composed of layers § Each component cannot “see” beyond the immediate layer with which it is interacting 3/12/2021 Web Services 38

HATEOAS q. A client sends a message in the form of a HTTP request.

HATEOAS q. A client sends a message in the form of a HTTP request. . q. . server responds in form of HTTP response 3/12/2021 Web Services 39

REST vs SOAP q Unlike SOAP services, REST is not bound to XML §

REST vs SOAP q Unlike SOAP services, REST is not bound to XML § CSV: comma separated values § JSON: Java. Script Object Notation (key value pairs) § Html is acceptable, human readable format, not machine processable q SOAP advantages include type safety of XML requests (although REST can still use XML) q REST advantage is ease of implementation, lightweight approach, better performance q REST: The service producer and service consumer need to have a common understanding of the context as well as the content being passed along as there is no standard set of rules to describe the REST Web services interface q SOAP: WSDL to define messages, operations, bindings and URI of service which can be more useful for publishing services to the world 3/12/2021 Web Services 40

Representation of Resources q. REST treats every content as a resource § Text files,

Representation of Resources q. REST treats every content as a resource § Text files, html pages, images, binary data. . q. REST uses XML q. And JSON 3/12/2021 Web Services 41

REST - Statelessness q. A RESTful Web service should not keep a client state

REST - Statelessness q. A RESTful Web service should not keep a client state on server § http: //localhost: 8080/User. Management/rest/User. Ser vice/users/1 § Will always return user whose id is 1 q. Advantages of Statelessness § Web services can treat each method request independently § Web services need not to maintain client's previous interactions § It simplifies application design 3/12/2021 Web Services 42

HTTP Methods q. Following well known HTTP methods are commonly used in REST based

HTTP Methods q. Following well known HTTP methods are commonly used in REST based architecture GET - Provides a read only access to a resource PUT - Used to create a new resource DELETE - Used to remove a resource. POST - Used to update a existing resource or create a new resource. § OPTIONS - Used to get the supported operations on a resource § § 3/12/2021 Web Services 43

More REST Examples / http Methods q A Web service for “user management” with

More REST Examples / http Methods q A Web service for “user management” with functionalities q Define REST service in Java using § Jersey REST Web Services framework for developing RESTful Web services in Java § Tomcat Web server for Java Servlet, http Web server in which Java code will run q PHP, Node. js, Perl, Python … can used as well to define RESTful services 3/12/2021 Web Services 44

HTTP Method, URI and Operation 3/12/2021 Web Services 45

HTTP Method, URI and Operation 3/12/2021 Web Services 45

HTTP Request q HTTP request’s major parts: q Verb: HTTP methods (GET, POST, DELETE,

HTTP Request q HTTP request’s major parts: q Verb: HTTP methods (GET, POST, DELETE, PUT) q URI: to identify the resource on server q HTTP Version: for example HTTP v 1. 1. q Request Header: Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc. q Request Body: Message content or Resource representation. 3/12/2021 Web Services 46

HTTP Response q HTTP Response parts: q Status/Response Code: 404 means resource not found

HTTP Response q HTTP Response parts: q Status/Response Code: 404 means resource not found and 200 means response is ok. q HTTP Version: for example HTTP v 1. 1. q Response Header: Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc. q Response Body: Response message content or Resource representation. 3/12/2021 Web Services 47

References q http: //W 3 schools. com q http: //searchsoa. techtarget. com/definition/serviceoriented-architecture q https:

References q http: //W 3 schools. com q http: //searchsoa. techtarget. com/definition/serviceoriented-architecture q https: //www. tutorialspoint. com/soap/ q http: //www. tutorialspoint. com/wsdl/ q https: //www. tutorialspoint. com/restful/ q http: //www. w 3. org/TR/2001/NOTE-wsdl-20010315 q Web services, Service Oriented Architectures and Cloud Computing, Douglas K. Bary, http: //www. servicearchitecture. com/index. html q http: //www. ibm. com/developerworks/library/ws-restwsdl/ 3/12/2021 Web Services 48