Presentation is loading. Please wait.

Presentation is loading. Please wait.

Service-Oriented Programming Introduction to service- oriented programming 1.

Similar presentations

Presentation on theme: "Service-Oriented Programming Introduction to service- oriented programming 1."— Presentation transcript:

1 Service-Oriented Programming Introduction to service- oriented programming 1

2 Aims  You should able to:  Articulate the motivation behind service-oriented programming  Understand the concept of web services  Understand the service-oriented architecture and web service standards  Build a web services using C# or Java  Develop an application that uses a public web services 2

3 Motivation: What does service-orientation mean?  What do we do when we have a complex problem?  We decompose it into sub problems (i.e., abstraction).  Object-Orientation defines an abstraction on the level of objects.  It allows to model, develop, and use software components as objects.  Service-Orientation defines an abstraction on the level of services.  It allows to model, develop, and use software systems as services. 3

4 The evolution of Programming Abstractions Figure: Evolution of Programming Abstractions (1) (1) Dr. Marcello La Rosa, QUT, Introduction to Web Services 4

5 What is Service-Oriented Programming (SOP)?  SOP is a programming paradigm that uses “services” as the building block to develop software applications.  Develop services.  Invoke services.  Combine services  Kernel component: Web Services 5

6 What is a Web Service?  Naïve answer: a service on the Web…  Different from a web application:  A web application is consumed by humans  Such as  A web service is consumed by programs  Such as Twitter APIs 6

7 What is a Web Service? (2)  W3C (World Wide Web Consortium) definition:  A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specially WSDL (web service description language)). Other systems interact with the Web service in a manner prescribed by its description using SOAP (simple object access protocol) messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web- related standards. 7

8 What is new in web services?  Global accessibility:  A web service is available on the Web  It leverages the powerful communication paradigm of the web  It is accessible via HTTP (cross firewall)  Standardization:  WSDL: for service description (  UDDI (Universal Description, Discovery and Integration): for service publish and discovery (  SOAP: for service invocation (  More standards…  They are XML-based… 8

9 More about web services  A Web service can be:  A self-contained business task  E.g., a funds withdrawal or funds deposit service  self-contained means it does not need other resources  business task is a simple step  A full-fledged business process  E.g., the automated purchasing of office suppliers  business process consists of several steps, or business tasks  An application  E.g., a life insurance application  A service-enabled resource  E.g., access to a particular back-end database containing patient medical records 9

10 What web service brings to SOP?  Foster software reuse  Deal with heterogeneity issues:  Using the same data types?  Using the same programming languages?  Using the same development platform?  Using the same operating systems?  Solution: provide XML-based Interfaces  XML is ubiquitous  traditional oop needs those items with ? 10

11 What web service brings to SOP? (2)  Deal with the accessibility issues:  Downloading libraries and including in the project?  Solution: access to functionalities on the web  Use existing networking infrastructure  HTTP is ubiquitous  traditional oop needs that 11

12 SOP as a new problem-solving methodology  Instead of develop an application to solve a complex problem from scratch, use the existing services:  decompose the problem to sub problems,  for each sub problem, select/or develop appropriate services,  compose these services together. 12

13 Current stage of SOP  Major IT companies have led the efforts  Microsoft, IBM, HP, Oracle, BEA, Sun, SAP…  A large number of web services online  Major IT companies deliver their functionalities as web services  Microsoft, Yahoo!, Google, Facebook, Twitter, Bing, Amazon, … you name it  there are 5814 Web services and 6610 mashups (SOP applications) published in programmableWeb.  Other search engines   ……  The Web is taking a step to transform from an information repository to a service repository 13

14 Web service commercial frameworks  Microsoft:  us/library/dd aspx us/library/dd aspx  IBM:   Oracle:  e/soa/overview/index.html e/soa/overview/index.html  Hewlett Packard  echnologies/soa-overview.html echnologies/soa-overview.html 14

15 An Example of SOP Applications:  Suppose we want to develop a web- based hotel query application that allows users to view the information of hotels. Given a location  Input: address  Output: a list of hotels, local weather, driving directions. 15

16 A SOP Example (2)  The process of developing this application contains the following steps:  Develop a hotel service:  Input: address  Output: a list of hotels  Develop a weather service:  Input: address  Output: local weather  Develop a route service:  Input: two addresses  Output: Driving directions  It is not trivial to develop any of the above services, so, let’s take a look at existing services on the web… 16

17 Hotel Service:  Expedia APIs:  ls/Version_3 ls/Version_3  Input: city, state  Output: the list of hotels (in Jason format)  name, average daily price, a short description  Demo.  17

18 Weather Service:  Weather underground weather API  pi/d/docs pi/d/docs  Input: Geocode  Output: current weather condition  weather, humidity, temperature, wind mph,…  Demo.  18

19 Route Service  The Google directions API  umentation/directions/ umentation/directions/  Input: origin, destination  Output: Driving direction  duration, instructions, distances,…  Demo  19

20 Behind SOP: Service-Oriented Architecture(SOA) Web Service Service Registry Service Consumer Service Provider Publish Find message exchange has defines Service Description UDDI Publication UDDI Inquiry SOAP WSDL UDDI Registry Web Browser 20

21 Service-Oriented Architecture(SOA)  Roles of interaction  Web services provider  Owns the Web service and implements the business logic  Hosts and controls access to the service  e.g., Microsoft, Amazon, Facebook, …  Web services requestor  Requires the certain functions to be satisfied  Looks for and invokes the service  e.g., a client program, a server, or another web service  Web services registry  Searchable directory where service descriptions can be published and searched  e.g., UDDI registry 21

22 Operations in SOA  Publish operation  Describing the Web service itself  Business information: information regarding the Web service provider or the implementer of the service  Service information: information about the nature of the Web service  Technical information: information about implementation details and the invocation methods for the Web service  Actual registration of the Web service  Storing the three basic categories of descriptive information about a service in the Web service registry 22

23 Operations in SOA (2)  Find operation  Discovering the services in the registry of the discovery agency  Search criteria: type of service, preferred price range, products associated with the service, company category  Can be specified  Statically at the design time to retrieve a service’s interface description for program development or  Dynamically (at run-time) to retrieve a service’s binding and location description for invocation.  Selecting the desired Web service from the search result  Manual selection  Automatic selection 23

24 Operations in SOA (3)  Bind operation  Service requestor invokes or initiates an interaction at run-time using the binding details in the service description to locate and contract to the service.  Two possibilities:  Direct invocation of the Web service by the Web service requestor  Mediation by the service agency when invoking the Web service 24

25 Service-Oriented Programming Web service standards and technologies: XML, WSDL, SOAP, REST. 25

26 XML  XML: eXtensible Markup Language  It is the universal format for structured documents and data on the Web  It is the common data format of Web services  It is a semi-structured data model 26

27 XML: Key concepts  Document  Elements  Attributes  Text  Others: namespace declarations, comments, processing instructions, … 27

28 Elements  Enclosed in Tags:  book, title, author, …  Start tag: End tag:  Empty element OR  Elements are ordered, may be repeated or nested 28

29 Basic XML Tag Syntax  Tags written as with HTML, but …  Case-sensitive names  Always need end tags  Special empty-element  Always quote attribute values  Some other constraints for tags  Start with a letter or underscore  After 1st character, numbers, -, and. are allowed  Cannot contain white-spaces. 29

30 Attributes  Associated to Elements, …   Attributes are unordered.  Attribute names must be unique.  Attributes cannot be nested (good for atomic value) 30

31 Attributes  Attributes provide metadata for the element  The value of each attribute must be enclosed in “ ”  If an element contains several attributes, then there is no comma in between  Same naming conventions as elements 31

32 Example: Database System Concepts, 5th Ed Silberschatz … 2006 Database System Concepts, 5th Ed Silberschatz …

33 WSDL  WSDL: Web Service Description Language  Pronounced “Whiz Dull”  XML-based  Why we need WSDL for web services?  Web services are designed to support machine-to-machine interaction  No human in the loop  Needs a specified and self-explanatory programming interface 33

34 What is included in a WSDL file?(1)  WSDL describes a service’s functionality  A service interface:  a list of operations that can be invoked by service users, such as getRoute, getMap,…  for each operation  a list of input parameters whose values need to be provided by service users, such as zipcode, address, …  a list of output parameters whose value will be returned to service users, such as directions, map image, …  By parsing a WSDL file, a program can:  determine if the service is suitable,  how to format the request,  how to handle the response. 34

35 What is included in a WSDL file?(2)  WSDL describes how to bind a service  Messaging style  Formatting (encoding) style  Transport protocol:  such as http, smtp, soap  WSDL describes where to locate a web service  a set of ports  A port defines the location of a web service, e.g., network address location or URL  By parsing a WSDL file, a program can:  Locate and bind a web service 35

36 WSDL document content  Abstract (interface) definitions  data type definitions  operation parameters  abstract description of service actions  set of operation definitions  Concrete (implementation) definitions  operation bindings  association of an endpoint with a binding  location/address for each binding 36

37 Example:  ECommerceService.wsdl ECommerceService.wsdl 37

38 SOAP (Simple Object Access Protocol)  It is the standard messaging protocol used by web services.  It supports inter application communication. 38

39 SOAP (2)  It codifies the use of XML as an encoding scheme for request and responses parameters using HTTP as a means for transport. Service provider Service requestor Application object (client) Application object (service provider) SOAP-based middleware SOAP messages exchanged on top of, HTTP, SMTP, or other transport Converts procedure calls to/from XML messages sent through HTTP or other protocols. 39

40 SOAP Message  SOAP messages are seen as enveloper where the application encloses the data to be sent.  A SOAP message consists of an element containing an optional and a mandatory element. SOAP envelope SOAP header header block SOAP body body block 40

41 SOAP header  Contains several header blocks  Contains information relevant to:  Security, QoS values, transaction  Example: 512 GRAAL-5YF3 …………… 41

42 SOAP Body  The SOAP body is the area of the SOAP message, where the application specific XML data (payload) being exchanged in the message is placed.  The element must be present and is an immediate child of the envelope. It may contain a number of child elements, called body entries, but it may also be empty. The element contains either of the following:  Application-specific data is the information that is exchanged with a Web service. The SOAP is where the method call information and its related arguments are encoded. It is where the response to a method call is placed, and where error information can be stored.  A fault message is used only when an error occurs.  A SOAP message may carry either application-specific data or a fault, but not both. 42

43 SOAP Body (Example) ACME Softener 35 Header Body Blocks Envelope 43

44 Example of SOAP Request

45 Example of SOAP Response

46 More example:  Sample SOAP Request and Response Message for Google's Web Service Interface (illustration purpose only)  wsdl.html wsdl.html 46

47 The SOAP Communication Model SOAP supports two possible communication styles:  remote procedure call (RPC) and  document (or message). RPC-style interaction Document-style interaction 47

48 RPC-style SOAP Services A remote procedure call (RPC)-style Web service appears as a remote object to a client application. The interaction between a client and an RPC-style Web service centers around a service- specific interface. Clients express their request as a method call with a set of arguments, which returns a response containing a return value. SOAP envelope SOAP body Method name orderGoods Input parameter 1 product item Input parameter 2 quantity SOAP envelope SOAP body Method return Return value order id

49 R6OP Example of RPC-style SOAP body Example of RPC-style SOAP response message RPC-style web services

50 Document (Message)-style SOAP Services o In the document-style of messaging, the SOAP contains an XML document fragment. The element reflects no explicit XML structure. o The SOAP run-time environment accepts the SOAP element as it stands and hands it over to the application it is destined for, unchanged. There may or may not be a response associated with this message. SOAP envelope SOAP body PurchaseOrder document -product item -quantity SOAP envelope SOAP body Acknowledgement document -order id 50

51 512 RightPlastics PSC Plastic Supplies Inc. Yara Valley Melbourne injection molder G-100T 2 Example of document-style SOAP body 51

52 SOAP Fault element o SOAP provides a model for handling faults. o It distinguishes between the conditions that result in a fault, and the ability to signal that fault to the originator of the faulty message or another node. The SOAP is the place where fault information is placed. 512 env:Sender m:InvalidPurchaseOrder Specified product did not exist Product number contains invalid characters

53 REST  Representational State Transfer Resource Client Boeing747.html Fuel requirements Maintenance schedule... The Client references a Web resource using a URL. A representation of the resource is returned (in this case as an HTML document). The representation (e.g., Boeing747.html) places the client in a new state. When the client selects a hyperlink in Boeing747.html, it accesses another resource. The new representation places the client application into yet another state. Thus, the client application transfers state with each resource representation. 53

54 Web Resource  Can be:  Information from database  e.g., invoice, resume, price, phone number,…  Image  e.g., map, photo,…  Audio  e.g., song, speech,…  Video  e.g., movie clip,  Others… 54

55 Resource Representations  Each resource is represented as a distinct Uniform Resource Identifier (URI)  Uniform Resource Name (URN)  e.g., isbn-10: or  Uniform Resource Locator (URL)  e.g., 55

56 The REST Design Pattern  Create a resource for every service.  Uniquely identify each resource with a logical URL.  Design your information to link to other information. That is, the information that a resource returns to a client should link to other information in a network of related information. 56

57 The REST Design Pattern (cont.)  All interactions between a client and a web service are done with simple operations. Most web interactions are done using HTTP and just four operations:  retrieve information (HTTP GET)  create information (HTTP PUT)  update information (HTTP POST)  delete information (HTTP DELETE) 57

58 REST Principles: Statelessness  Every HTTP request is isolated from others.  Every HTTP request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server.  All of the information related to application states is kept entirely on the client side.  Application states are maintained if requests need to be made in a certain order, for example: make payment after adding products to a shopping cart 58

59 Learn by Example  Parts Depot, Inc has deployed some web services to enable its customers to:  get a list of parts  get detailed information about a particular part  submit a Purchase Order (PO) 59

60 The REST way of Designing the Web Services Web Server HTTP POST URL 3 PO (HTML/XML) HTTP GET request URL 1 HTTP response URL to submitted PO Parts List Part Data PO HTTP response Response (HTML/XML doc) HTTP response Response (HTML/XML doc) HTTP GET request URL 2 60

61 The First Web Service o Service: Get a list of parts o The web service makes an available URL to a parts list resource. A client uses this URL to get the parts list: o o Note that how the web service generates the parts list is completely transparent to the client. This is loose coupling. 61

62 Data Returned - Parts List o Each resource is identified as a URL. o Note that the parts list has links to get detailed info about each part. o This is a key feature of the REST design pattern. The client transfers from one state to the next by examining and choosing from among the alternative URLs in the response document. 62

63 The second Web Service o Get detailed information about a particular part o The web service makes available a URL to each part resource. For example, here's how a client requests a specific part: o o Data returned Widget-A This part is used within the frap assembly

64 The Third Web Service o Submit a Purchase Order (PO) o The web service allows users to create a new purchase order and insert it into the database. For example, here is a HTTP request a user will make: o URL: o Method: POST o Request body: o Returns: o 201 Created &Location o 401 Unauthorized o 415 Unsupported Media Type /14/ A

65 65 weather service: IMDB service: Calculator service: You can test the services via the following link: here are some urls, source codes and documentations of sample services Web Service Examples

Download ppt "Service-Oriented Programming Introduction to service- oriented programming 1."

Similar presentations

Ads by Google