service-oriented architectures for the web

50
Service-Oriented Architectures for the Web Dr Kevin McManus http://staffweb.cms.gre.ac.uk/~mk05/web/d otnet/

Upload: avak

Post on 17-Jan-2016

74 views

Category:

Documents


2 download

DESCRIPTION

Dr Kevin McManus http://staffweb.cms.gre.ac.uk/~mk05/web/dotnet/. Service-Oriented Architectures for the Web. Talk About. What is a Service-Oriented Architecture? Web Services REST, SOAP, WSDL, UDDI Web service integration ASP.NET, PHP Problems with SOA / WS. SOA?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Service-Oriented Architectures for the Web

Service-Oriented Architectures for the Web

Dr Kevin McManushttp://staffweb.cms.gre.ac.uk/~mk05/web/dotnet/

Page 2: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 2

Service Oriented Architectures for the Web

Talk About

• What is a Service-Oriented Architecture?

• Web Services• REST, SOAP, WSDL, UDDI

• Web service integration• ASP.NET, PHP

• Problems with SOA / WS

Page 3: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 3

Service Oriented Architectures for the Web

SOA?• A paradigm for organizing and utilizing

distributed capabilities that may be under the control of different ownership domains†

• distributed systems architecture• views applications as service providers• allows other applications to utilise services

• creating new processes• creating new applications• creating new business opportunities• creating new services

† Reference Model for Service Oriented Architecture 1.0, OASIS Standard, 12 October 2006

Page 4: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 4

Service Oriented Architectures for the Web

S O Architecture

• Interface driven• separation between the interface and the

implementation

• Consumers only need to understand the service description and the service interface

• Interface is defined by type of messages the service can send and receive

Page 5: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 5

Service Oriented Architectures for the Web

SO Architectural Principles• Reuse, granularity, modularity,

componentization, and interoperability• Compliance to standards • Services identification and categorization• Service encapsulation• Loose coupling • Service contract• Service abstraction • Service autonomy • Service statelessness• Service discoverability

(source Wikipedia)

Page 6: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 6

Service Oriented Architectures for the Web

Web Services

• Enable SOAs for the Web• Standards based

• IETF, W3C, OASIS

• Contract Driven• SOAP + WSDL

• Self describing• WSDL

• Discoverable• UDDI

Page 7: Service-Oriented Architectures for the Web

© 2012 University of Greenwich

Service Oriented Architectures for the Web

Web ServicesEvolution of the Web

Generation 2Web Applications

HTML

Generation 1Static HTML

HTML

HTML, XML

Generation 3Web Services

XML

Page 8: Service-Oriented Architectures for the Web

© 2012 University of Greenwich

Service Oriented Architectures for the Web

Origin of Web Services

web pagethe web (HTTP)

client object server objectLAN or WAN

client object server objectthe webHTTP + XML

plus distributed object systems - DCOM, RMI, CORBA

resulting in XML based web services

Page 9: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 9

Service Oriented Architectures for the Web

Web Service Example

Brokering application

authentication

service

currency conversion

service

share price service

HTMLHTTP

XMLHTTP

XMLHTTP

XMLHTTP

Page 10: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 10

Service Oriented Architectures for the Web

What is a Web Service?

• A URI that returns XML

• A Web Service combines the best features of distributed computing and portals and eliminates the worst• Provides a mechanism for invoking methods

remotely• Uses Web standards i.e. HTTP, XML

• considered scalable and safe• allowed through corporate firewall

• unlike previous distribution technologies

Page 11: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 11

Service Oriented Architectures for the Web

What is a Web Service?• The solution?• A Web Service exposes functionality to a

consumer• over the Internet or intranet• a programmable URL• functions you can call over the Internet

• Based on Web standards• HTTP, XML, SOAP, WSDL, UDDI, with more to come

• Can be implemented in any language on any platform• reusable black box components

Page 12: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 12

Service Oriented Architectures for the Web

Web Services• Not tied to any specific implementations• Three technologies most often mentioned are:

• SOAP (Simple Object Access Protocol)• provides an XML based protocol for exchanging information

• WSDL (Web Services Description Language)• an XML based language for describing web services and

how to access them

• UDDI (Universal Description, Discovery and Integration specification)

• a method for publishing and finding web service descriptions e.g. as described in WSDL

• Other technologies• ebXML (ISO, OASIS), WSS, REST (not really a technology)

Page 13: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 13

Service Oriented Architectures for the Web

What is a Web Service?• Web Services allow you to interconnect:

• different companies• many / any devices• applications• different clients

• not just browsers

• Distribution and integration of application logic• Enable the programmable (semantic) Web

• not just the purely interactive Web

• Web Services are loosely coupled

Page 14: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 14

Service Oriented Architectures for the Web

SOAP• Initially developed by Microsoft as a Simple

Object Access Protocol circa 1998• Adopted by W3C in 2000

• latest is SOAP version 1.2 2003

• A lightweight protocol for exchanging information in a distributed, heterogeneous environment

• Cross-platform interoperability• OS, object model & programming language neutral• hardware independent• transmission protocol independent• works over existing Internet infrastructure

Page 15: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 15

Service Oriented Architectures for the Web

SOAP

• Guiding principle: “Invent no new technology”

• Builds on key Internet standards• SOAP ≈ HTTP + XML

• The SOAP specification defines:• the SOAP message format• how to send messages• how to receive responses• data encoding

Page 16: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 16

Service Oriented Architectures for the Web

SOAP is not…

• Objects-by-reference• remote procedure call• distributed garbage collection

• Push technology• bi-directional HTTP

• Complicated• it doesn’t try to solve every distributed

computing problem • it can be easily implemented

Page 17: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 17

Service Oriented Architectures for the Web

SOAP

• SOAP requests are HTTP POST requests

POST /WebCalculator/Calculator.asmx HTTP/1.1Content-Type: text/xmlSOAPAction: "http://tempuri.org/Add"Content-Length: 386

<?xml version="1.0"?><soap:Envelope ...> ...</soap:Envelope>

Page 18: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 18

Service Oriented Architectures for the Web

SOAP

SOAP Message

SOAP Envelope

SOAP Header

SOAP Body

Message Name & Data

Headers

Headers

XML-encoded SOAP message name & data

<Body> contains SOAP message name

Individual headers

<Header> encloses headers

<Envelope> encloses payload

Protocol binding headers

The complete SOAP message

Page 19: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 19

Service Oriented Architectures for the Web

SOAPMessage Format

• XML document using the SOAP schema

<?xml version="1.0"?><soap:Envelope ...> <soap:Header ...> ... </soap:Header> <soap:Body> <Add xmlns="http://tempuri.org/"> <number1>12</number1> <number2>16</number2> </Add> </soap:Body></soap:Envelope>

Page 20: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 20

Service Oriented Architectures for the Web

SOAPServer Response

• Server responds with a result message

HTTP/1.1 200 OK...Content-Type:text/xmlContent-Length: 391

<?xml version="1.0"?><soap:Envelope ...> <soap:Body> <AddResult xmlns="http://tempuri.org/"> <result>28.0</result> </AddResult> </soap:Body></soap:Envelope>

Page 21: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 21

Service Oriented Architectures for the Web

SOAPEncoding Complex Data

• Data structures are serialized as XML

<soap:Envelope ...> <soap:Body> <GetStockDataResult xmlns="http://tempuri.org/"> <result> <Description>Plastic Novelties Ltd</Description> <Price>129</Price> <Ticker>PLAS</Ticker> </result> </GetStockDataRseult> </soap:Body></soap:Envelope>

Page 22: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 22

Service Oriented Architectures for the Web

WSDL• Web Services Description Language• XML schema for describing a Web Service

contract1.Service interface definition

abstract semantics for Web Service

2.Service implementation definitionconcrete end points and network addresses where

Web Service can be invoked

• Describes a set of SOAP messages and how the messages are exchanged

Page 23: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 23

Service Oriented Architectures for the Web

WSDL<definitions> <types> Data types that are used by the web service (XSD) </types> <message> Defines the data elements of an operation </message> <portType> Describes a web service, the operations that can be performed, and the messages that are involved. </portType> <binding> Defines the message format and protocol details for each port </binding></definitions>

Page 24: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 24

Service Oriented Architectures for the Web

UDDI• Universal Description, Discovery, and Integration

• OASIS standard

• Industry Initiative to address discovery• a registration database for Web Services

• Yellow pages

• Specifications• schema for service providers and descriptions• API for publishing and searching• developed on industry standards (XML, HTTP, TCP/IP, SOAP)• applies to both XML and non-XML services

• Implementation• public and private instances of specification

Page 25: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 25

Service Oriented Architectures for the Web

REST• Representational State Transfer• Originally† referred to a collection of architectural

principles:• a stateless client/server protocol

• HTTP

• a set of well-defined operations• GET, POST, DELETE

• a universal syntax for resource-identification• URL

• the use of hypermedia• HTML, XML

• Simply a URL that returns XML† Fielding, Roy T., Architectural Styles and the Design of Network-based Software Architectures, PhD thesis (2000)

Page 26: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 26

Service Oriented Architectures for the Web

RESTful SOA• Next time you find yourself creating a new intranet web

page that provides really useful information

Think SOA

• Don’t create a traditional db driven HTML web page• Create a restful web service

• a db driven XML web page• accepts GET/POST just like a traditional web page• use XSLT to transform the XML into an HTML page

• People like us will no longer need to screen scrape HTML to use the page to create new / one-off / custom applications

Page 27: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 27

Service Oriented Architectures for the Web

ASP.NET

• Fully tooled up support from Visual Studio• Microsoft taking a lead

• Three mouse clicks and your Web Service is fully SOAPed• with WSDL and UDDI

• A number of changes in Visual Studio 2005• mostly improvements

Page 28: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 28

Service Oriented Architectures for the Web

ASP.NET Web Service

Create a new web site and select ASP.NET Web

Service

Choose File System and your favourite

language

Page 29: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 29

Service Oriented Architectures for the Web

ASP.NET Web Service

VS05 gives you a Hello World template

Page 30: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 30

Service Oriented Architectures for the Web

ASP.NET Web Service

• Build and run (CtlF5) VS05 fires up a web server on a new port to test the project…

… and uses our favourite browser to

demonstrate!

Page 31: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 31

Service Oriented Architectures for the Web

ASP.NET Web Service

Follow this link to see the WSDLFollow this link to test

the service

Page 32: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 32

Service Oriented Architectures for the Web

ASP.NET Web Service

This HTML form tests the POST service

Page 33: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 33

Service Oriented Architectures for the Web

ASP.NET Web Service

VS05 no longer creates a GET

service by default

Returned value with XML wrapper

Page 34: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 34

Service Oriented Architectures for the Web

ASP.NET Web Service

Right click the project in the Solution

Explorer and add a Web Configuration

File

Page 35: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 35

Service Oriented Architectures for the Web

ASP.NET Web Service

Add some stanzas to persuade VS05 to

create all three protocols

Page 36: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 36

Service Oriented Architectures for the Web

ASP.NET Web Service [WebMethod] public string helloWorld(int mess) { if (mess == 1) { return "Hello world :-)"; } else if (mess == 2) { return "Howdy howdy howdy" ; } else { return "I beg your pardon?" ; } }

[WebMethod] public string fufu(string foo) { return foo + foo + foo + foo; }

Add some code to make the service a little more

interesting…

… and rebuild

Page 37: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 37

Service Oriented Architectures for the Web

ASP.NET Web Service

VS05 gives us forms to test both web methods

Page 38: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 38

Service Oriented Architectures for the Web

ASP.NET Web Service• So now we want to create a SOAP client to test

the SOAP service• This is where VS05 runs into some problems• Starting a new project kills the web server that

VS05 created for us to test our web service• We could add a SOAP client to our existing web

project but that rather defeats the object of the exercise

• So try some PHP instead

Page 39: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 39

Service Oriented Architectures for the Web

PHP

• Offered three SOAP implementations• NuSOAP• ezSOAP• PEAR::SOAP

• All implemented using PHP

• PHP5 includes a SOAP class• created by Zend in C/C++• supports subsets of SOAP 1.1, SOAP 1.2 and

WSDL 1.1 specifications

Page 40: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 40

Service Oriented Architectures for the Web

PHP

<?php

$client = new

SoapClient("http://localhost:1417/WebSite1/Service.asmx?WSDL");

echo $client->helloWorld(2)->helloWorldResult;

?>

Call the web method described in the WSDL

passing an integer argument with the value 2

and get the result

Instantiate a new SOAP client and tell it where to

find the WSDL

Page 41: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 41

Service Oriented Architectures for the Web

PHP

Something wrong here…

… it should have replied “Howdy howdy howdy”

This return value has been unpacked from it’s

XML wrapper

Page 42: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 42

Service Oriented Architectures for the Web

PHP

Aha!The web method was

expecting a complexType

Check the WSDL to see what we are doing wrong

Page 43: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 43

Service Oriented Architectures for the Web

PHP

<?php

$client = new

SoapClient("http://localhost:1417/WebSite1/Service.asmx?WSDL");

echo $client->helloWorld(array('mess' => 2))->helloWorldResult;

?>

The web method expected a name=value pair…

… just like GET or POST

Page 44: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 44

Service Oriented Architectures for the Web

PHP Web Service Client• Now that we have figured out how to

interface a PHP client to a .NET web service…

• Create a simple PHP web application that uses the .NET web service• a form with two inputs and a submit button

• not unlike the form that Visual Studio creates to test the web service

• the application submits form input to itself, passes the input to the web service and returns the result to the user

Page 45: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 45

Service Oriented Architectures for the Web

<body><h1> WebSite using SOAP</h1><form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"><p><?php$mess = ( isset($_POST['mess']) ) ? $_POST['mess'] : '1';$foo = ( isset($_POST['foo']) ) ? $_POST['foo'] : 'bar';?><input type="text" name="mess" value="<?php echo $mess ?>"/><input type="text" name="foo" value="<?php echo $foo ?>"/><input type="submit" /></p><p><?php$mess = (integer)$mess;$client = new SoapClient("http://localhost:1038/WebSite4/Service.asmx?WSDL");echo($client->helloWorld(array('mess'=>$mess))->helloWorldResult);echo '<br /><br />';echo($client->fufu($_POST)->fufuResult);?> </p></form></body>

$_POST is an array containing the appropriate

name value pair

Typecast the string POSTed back from the

form

Page 46: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 46

Service Oriented Architectures for the Web

PHP

Consuming ASP.NET web services using PHP has

become remarkably simple

Page 47: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 47

Service Oriented Architectures for the Web

Handling XML Data• If you are handling XML data then why

bother with all that SOAP?• REST places less load on the server

• so simply return the XML from GET/POST requests

• So why SOAP?• to linearise and ASCII (XML) transport your

complicated objects• use power tools• avoid having to get your hands dirty with XML

Page 48: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 48

Service Oriented Architectures for the Web

Some Problems• Evolving and changing standards• Tool support• Security (OASIS WSS standard)• Versioning• XML serialisation is slow• XML data is bulky

• enormous redundancy

• Why SOAP if you can REST?• maybe because you aren’t interested in XML?

Page 49: Service-Oriented Architectures for the Web

© 2012 University of Greenwich 49

Service Oriented Architectures for the Web

Summary• Web Services

• A new(ish) paradigm for Internet development• Deliver applications as services

• using existing web technologies

• Third-generation Internet• n-tier systems

• Enabling technology for the semantic web• with or without SOAP• preferably with WSDL and UDDI

• More than just hype

Page 50: Service-Oriented Architectures for the Web

© 2012 University of Greenwich

Service Oriented Architectures for the Web

Questions?