670 likes | 850 Views
Service-Oriented Programming. Introduction to service-oriented programming. 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
E N D
Service-Oriented Programming Introduction to service-oriented programming
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
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.
The evolution of Programming Abstractions Figure: Evolution of Programming Abstractions (1) (1) Dr. Marcello La Rosa, QUT, Introduction to Web Services
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
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 http://www.weather.com • A web service is consumed by programs • Such as Twitter APIs https://dev.twitter.com/docs/api/1
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.
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 (www.w3.org/TR/wsdl) • UDDI (Universal Description, Discovery and Integration): for service publish and discovery (http://uddi.xml.org/) • SOAP: for service invocation (www.w3.org/TR/SOAP/) • More standards… • They are XML-based…
More about web services • A Web service can be: • A self-containedbusiness 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
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 ?
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
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.
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 • http://www.webservicelist.com/ • http://www.biocatalogue.org/ …… • The Web is taking a step to transform from an information repository to a service repository
Web service commercial frameworks • Microsoft: • http://msdn.microsoft.com/en-us/library/dd456779.aspx • IBM: • http://www-01.ibm.com/software/solutions/soa/ • Oracle: • http://www.oracle.com/us/products/middleware/soa/overview/index.html • Hewlett Packard • http://h71028.www7.hp.com/enterprise/w1/en/technologies/soa-overview.html
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.
ASOP 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…
Hotel Service: • Expedia APIs: • http://developer.ean.com/docs/read/hotels/Version_3 • Input: city, state • Output: the list of hotels (in Jason format) • name, average daily price, a short description • Demo. • http://vhost3.cs.rit.edu/Application/
Weather Service: • Weather underground weather API • http://www.wunderground.com/weather/api/d/docs • Input: Geocode • Output: current weather condition • weather, humidity, temperature, wind mph,… • Demo. • http://vhost3.cs.rit.edu/Application/
Route Service • The Google directions API • https://developers.google.com/maps/documentation/directions/ • Input: origin, destination • Output: Driving direction • duration, instructions, distances,… • Demo • http://vhost3.cs.rit.edu/Application/
UDDI Registry UDDI Publication UDDI Inquiry SOAP WSDL Behind SOP: Service-Oriented Architecture(SOA) Service Registry Publish Find Web Browser Service Provider Service Consumer defines message has Web Service exchange Service Description Web Service
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
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
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
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
Service-Oriented Programming Web service standards and technologies: XML, WSDL, SOAP, REST.
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
XML: Key concepts • Document • Elements • Attributes • Text • Others: namespace declarations, comments, processing instructions, …
Elements • Enclosed in Tags: • book, title, author, … • Start tag: <book> End tag: </book> • Empty element <red></red> OR <red/> • Elements are ordered, may be repeated or nested
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.
Attributes • Associated to Elements, … • <book price=“20”> • Attributes are unordered. • Attribute names must be unique. • Attributes cannot be nested (good for atomic value)
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
Example: <book price = “95” currency = “USD”> <title> Database System Concepts, 5th Ed</title> <author> Silberschatz </author> … <year> 2006 </year> </book>
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
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.
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
WSDL document content • Abstract (interface) definitions • <types> data type definitions • <message> operation parameters • <operation> abstract description of service actions • <portType> set of operation definitions • Concrete (implementation) definitions • <binding> operation bindings • <port> association of an endpoint with a binding • <service> location/address for each binding
Example: • http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl
SOAP (Simple Object Access Protocol) • It is the standard messaging protocol used by web services. • It supports inter application communication.
Service provider Service requestor Application object (service provider) Application object (client) SOAP-based middleware 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. SOAP (2) • It codifies the use of XML as an encoding scheme for request and responses parameters using HTTP as a means for transport.
SOAP envelope SOAP header header block body block SOAP body SOAP Message • SOAP messages are seen as enveloper where the application encloses the data to be sent. • A SOAP message consists of an <Envelope> element containing an optional <Header> and a mandatory <Body> element.
SOAP header • Contains several header blocks • Contains information relevant to: • Security, QoS values, transaction • Example: <env:Envelope xmlns:env=“http://www.w3.org/2003/05/soap-envelope” > … <env:Header> <tx:transaction-id xmlns:tx=”http://www.transaction.com/transaction” env:mustUnderstand=”true”> 512 </tx:transaction-id> <notary:tokenxmlns:notary=”http://www.notarization-services.com/token” env:mustUnderstand=”true”> GRAAL-5YF3 </notary:token> </env:Header> …………… </env:Envelope>
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 <Body> 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 <Body> element contains either of the following: • Application-specific data is the information that is exchanged with a Web service. The SOAP <Body> 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.
SOAP Body (Example) <?xml version='1.0' ?> <env:Envelopexmlns:env="http://www.w3.org/2002/06/soap-envelope" > <env:Header> <t:transactionID xmlns:t="http://intermediary.example.com/procurement" env:role="http://www.w3.org/2002/06/soap-envelope/role/next" env:mustUnderstand="true" > 57539 </t:transactionID> </env:Header> <env:Body> <m:orderGoods env:encodingStyle="http://www.w3.org/2002/06/soap-encoding" xmlns:m="http://example.com/procurement"> <m:productItem> <name>ACME Softener</name> </m:productItem> <m:quantity> 35 </m:quantity> </m:orderGoods> </env:Body> </env:Envelope> Envelope Header Blocks Body
Example of SOAP Request <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/”> <SOAP-ENV:Header> <t:transId xmlns:t=“http://a.com/trans”>345</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=“http://a.com/Calculator”> <n1>3</n1> <n2>4</n2> </m:Add> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Example of SOAP Response <SOAP-ENV:Envelope xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/” SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/”> <SOAP-ENV:Header> <t:transId xmlns:t=“http://a.com/trans”>345</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:AddResponsexmlns:m=“http://a.com/Calculator”> <result>7</result> </m:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
More example: • Sample SOAP Request and Response Message for Google's Web Service Interface (illustration purpose only) • http://www.w3.org/2004/06/03-google-soap-wsdl.html
The SOAP Communication Model • SOAP supports two possible communication styles: • remote procedure call (RPC) and • document (or message). RPC-style interaction Document-style interaction
SOAP envelope SOAP envelope SOAP body SOAP body Method name orderGoods Method return Input parameter 1 product item Return value order id Input parameter 2 quantity 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.
RPC-style web services <env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope” xmlns:m="http://www.plastics_supply.com/product-prices"> <env:Header> <tx:Transaction-id xmlns:t=”http://www.transaction.com/transactions” env:mustUnderstand='1'> 512 </tx:Transaction-id> </env:Header> <env:Body> <m:GetProductPrice> <product-id> 450R6OP </product-id > </m:GetProductPrice > </env:Body> </env:Envelope> Example of RPC-style SOAP body <env:Envelope xmlns:SOAP=“http://www.w3.org/2003/05/soap-envelope” xmlns:m="http://www.plastics_supply.com/product-prices"> <env:Header> <--! – Optional context information --> </env:Header> <env:Body> <m:GetProductPriceResponse> <product-price> 134.32 </product-price> </m:GetProductPriceResponse> </env:Body> </env:Envelope> Example of RPC-style SOAP response message
In the document-style of messaging, the SOAP <Body> contains an XML document fragment. The <Body> element reflects no explicit XML structure. The SOAP run-time environment accepts the SOAP <Body> 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 envelope SOAP body SOAP body • Acknowledgement • document • order id • PurchaseOrder • document • product item • quantity Document (Message)-style SOAP Services