SENGER 060504 Web Services

Embed Size (px)

Citation preview

  • 8/14/2019 SENGER 060504 Web Services

    1/36

    Web ServicesWeb Services

    Martin SengerMartin Senger

    [email protected]@ebi.ac.uk

  • 8/14/2019 SENGER 060504 Web Services

    2/36

    AbstractAbstract

    Web Services is a technologyWeb Services is a technology

    applicable for computationallyapplicable for computationally

    distributed problems, includingdistributed problems, including

    access to large databasesaccess to large databases

    What other technologies were/areWhat other technologies were/are

    available and how they compare withavailable and how they compare with

    Web Services?Web Services?The main buzzwords:The main buzzwords:

    Integration & Standardization & AccessIntegration & Standardization & Access

    by programsby programs

  • 8/14/2019 SENGER 060504 Web Services

    3/36

    Why to use more than oneWhy to use more than one

    computer?computer? Distributed resourcesDistributed resources

    access to shared dataaccess to shared data

    access to shared programsaccess to shared programs

    access to CPU (e.g. many desktop PCsaccess to CPU (e.g. many desktop PCs

    together), to memory, to special devicestogether), to memory, to special devices

    (e.g. printer)(e.g. printer) Complete independence on theComplete independence on the

    internal implementationinternal implementation

  • 8/14/2019 SENGER 060504 Web Services

    4/36

    DistributedDistributed

    architecturearchitecture gives

    gives

    access to distributed resourcesaccess to distributed resources

    development encapsulationdevelopment encapsulation

    maintainability, re-usability, legacy-maintainability, re-usability, legacy-

    awarenessawareness

    implementation independenceimplementation independence

    requires

    requires adding a communication layeradding a communication layer

    between partsbetween parts

    synchronization of effortssynchronization of efforts includin such nast thin s as distributedincludin such nast thin s as distributed

  • 8/14/2019 SENGER 060504 Web Services

    5/36

    Sending

    requests,

    getting

    results

    Waiting for

    requests(known location,

    known port)

    Communication protocol, Data format

    Distributed architecture

    Basic questions are:

    What kind of protocol to use, and whatdata to transmit

    What to do with requests on the serverside

  • 8/14/2019 SENGER 060504 Web Services

    6/36

    Sending

    requests,

    getting

    results

    Waiting for

    requests(known location,

    known port)

    Data as name/value pairs

    Traditional CGI-based approach

    cgi-bin scripts:

    Data transmitted as name-value pairs(HTML forms)

    Transport over (state-less) HTTP protocol

    no standards for keeping user sessions(state-fullness)

  • 8/14/2019 SENGER 060504 Web Services

    7/36

    Sending

    requests,

    getting

    results

    Waiting for

    requests(known location,

    known port)

    Data in binary format

    CORBA-based approach

    CORBA:

    Data transmitted as objects (at least itlooks like that)

    Transport (usually) over well standardisedIIOP protocol

    user sessions (state-fullness) very inter-

  • 8/14/2019 SENGER 060504 Web Services

    8/36

    Sending

    requests,

    getting

    results

    Waiting for

    requests(known location,

    known port)

    Data in XML format

    SOAP-based communication

    SOAP:

    Data in a well-defined XML formatTransport over various protocols

    HTTP, SMTP are the most used, perhapsbecause they are firewall-friendly

    server side: either an RPC call or a

  • 8/14/2019 SENGER 060504 Web Services

    9/36

    Web servicesWeb services

    A collection of XML-basedA collection of XML-basedtechnologies developed by the e-technologies developed by the e-

    business community to address issuesbusiness community to address issues

    of:of: service discoveryservice discovery

    interoperable data exchange and/orinteroperable data exchange and/or

    application invocationapplication invocation service compositions (workflow, businessservice compositions (workflow, business

    processes)processes)

    Major developers include:Major developers include:

  • 8/14/2019 SENGER 060504 Web Services

    10/36

    W3C (working group)W3C (working group)

    definitiondefinition

    "A Web service is a software"A Web service is a software

    applicationapplication identified by a URIidentifiedby a URI, whose, whose

    interfaces and bindings are capableinterfaces and bindings are capableof being defined,of being defined, described anddescribed and

    discovereddiscoveredas XML artefacts. A Webas XML artefacts. A Web

    service supports direct interactionsservice supports direct interactions

    with other software agents usingwith other software agents usingXMLXML

    based messagesbased messages exchanged viaexchanged via

    internet-based protocolsinternet-based protocols."."

    - - -htt : www.w3c.or TR 2002 WD-wsa-re s-

  • 8/14/2019 SENGER 060504 Web Services

    11/36

    Web Services ArchitectureWeb Services Architecture

    Let a program click on a web page

  • 8/14/2019 SENGER 060504 Web Services

    12/36

    Web Services StackWeb Services Stack

  • 8/14/2019 SENGER 060504 Web Services

    13/36

    SOAPSOAP

    SSimpleimple OObjectbject AAccessccess PProtocolrotocol

    http://www.w3c.org/TR/SOAP/http://www.w3c.org/TR/SOAP/

    A lightweight protocol for exchangeA lightweight protocol for exchangeof information in a decentralised,of information in a decentralised,

    distributed environmentdistributed environment

    Two different styles to use:Two different styles to use:

    to encapsulate RPC calls using theto encapsulate RPC calls using the

    extensibility and flexibility of XMLextensibility and flexibility of XML

    or to deliver a whole documentor to deliver a whole document

    without any method calls encapsulatedwithout any method calls encapsulated

  • 8/14/2019 SENGER 060504 Web Services

    14/36

    Request:Request:setHelloMessasetHelloMessa

    gege

    Request:getHelloMessag

    e

  • 8/14/2019 SENGER 060504 Web Services

    15/36

    XML Messaging UsingXML Messaging Using

    SOAPSOAP

  • 8/14/2019 SENGER 060504 Web Services

    16/36

    WSDLWSDL

    WWebeb SServiceservices DDefinitionefinition LLanguageanguage

    http://www.w3.org/TR/wsdl/http://www.w3.org/TR/wsdl/

    An XML-based language forAn XML-based language fordescribing Web Servicesdescribing Web Services

    what the service does (description)what the service does (description)

    how to use it (method signatures)how to use it (method signatures)

    where to find the servicewhere to find the service

    ItIt does notdoes notdepend on the underlyingdepend on the underlying

    protocolprotocol

    -But: It is not much human-readable

  • 8/14/2019 SENGER 060504 Web Services

    17/36

    Hello.wsdlHello.wsdl

    message="intf:setHelloMessageResponse"/>

  • 8/14/2019 SENGER 060504 Web Services

    18/36

    UDDI (and alternatives)UDDI (and alternatives)

    UUniversalniversal DDescription,escription, DDiscovery andiscovery andIIntegrationntegration

    http://www.uddi.orghttp://www.uddi.org

    UDDI creates a platform-independent,UDDI creates a platform-independent,open framework & registry for:open framework & registry for:

    Describing servicesDescribing services

    Discovering businessesDiscovering businesses

    Integrating business servicesIntegrating business services

    The UDDI may be less used thanThe UDDI may be less used than

    predicted, especially on the Internetpredicted, especially on the Internetlevel

  • 8/14/2019 SENGER 060504 Web Services

    19/36

    BioMobyBioMobyhttp://biomoby.orghttp://biomoby.org

  • 8/14/2019 SENGER 060504 Web Services

    20/36

    A Web Service exampleA Web Service example

    in Javain Java

    SOAP-awareSOAP-aware

    ServletServlet(e.g. Apache Axis)(e.g. Apache Axis)

    Any classprocessing

    the incomingrequests

    (business logic

    Any classprocessing

    the incomingrequests

    (business logic

    Any classprocessing

    the incoming

    requests(business logic

    Any classAny class

    processingprocessing

    the incomingthe incomingrequestsrequests

    (business logic(business logic

    HTTP ServerHTTP Server

    Servlet engine (e.g. Apache Tomcat)Servlet engine (e.g. Apache Tomcat)

    Sending

    requests,

    getting

    results

  • 8/14/2019 SENGER 060504 Web Services

    21/36

    Usual principles of JavaUsual principles of Java

    toolkitstoolkits Writing server is easier than writing clientsWriting server is easier than writing clients

    (but only regarding the toolkit, not the(but only regarding the toolkit, not thebusiness logic)business logic)

    ServersServers maymay be written independently onbe written independently on

    the used toolkitthe used toolkit Always test interoperability with a non-Always test interoperability with a non-

    Java client (because of data serializationJava client (because of data serializationand de-serialization)and de-serialization)

    Steps:Steps: write your service implementationwrite your service implementation make all your classes available to the toolkitmake all your classes available to the toolkit deploy your servicedeploy your service (usually done just once)(usually done just once)

    restart the whole servlet enginerestart the whole servlet engine

    test it with a client requesttest it with a client request

  • 8/14/2019 SENGER 060504 Web Services

    22/36

    Java SOAP ToolkitsJava SOAP Toolkits

    Apache SOAP (was IBMs SOAP4J)Apache SOAP (was IBMs SOAP4J)

    Apache Axis (a follow-on to theApache Axis (a follow-on to the

    Apache SOAP)Apache SOAP)

    and many othersand many others

    but lets stay with Apache Axis:but lets stay with Apache Axis:

    http://http://ws.apache.orgws.apache.org/axis//axis/

    http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/http://ws.apache.org/axis/
  • 8/14/2019 SENGER 060504 Web Services

    23/36

    package hello;public interface HelloWorld {

    String getHelloMessage();void setHelloMessage (String newHello);

    }

    package hello;public class HelloWorldService

    implements HelloWorld {String message = "Hello, world!";

    public String getHelloMessage() {return message;

    }public void setHelloMessage (String newMessage) {

    message = newMessage;}

    }

    hello/HelloWorld.java

    hello/HelloWorldService.java

    H ll W ldCli t j

  • 8/14/2019 SENGER 060504 Web Services

    24/36

    import org.apache.axis.client.*;public class HelloWorldClient {

    public static void main (String [] args) {try {// prepare the call (the same for all called methods)

    Call call = (Call) new Service().createCall();call.setTargetEndpointAddress(new java.net.URL("http://localhost:8080/axis/services/Hello"));

    // call "get message"if (args.length == 0) {call.setOperationName ("getHelloMessage");String result = (String) call.invoke ( new Object [] {} );

    System.out.println (result);System.exit (0);

    }

    // call "set message" and afterwards "get message"call.setMaintainSession (true); // TRY also without this line...call.setOperationName ("setHelloMessage");

    call.invoke ( new Object [] { args[0] } );call.setOperationName ("getHelloMessage");System.out.println (call.invoke ( new Object [] {} ));

    } catch (Exception e) {System.err.println ("ERROR:\n" + e.toString());

    }}

    }

    HelloWorldClient.java

    Generated forGenerated for

  • 8/14/2019 SENGER 060504 Web Services

    25/36

    Generated forGenerated for

    HelloWorldHelloWorld

    HelloWorldServiceLocator

    implements

    HelloWorldService

    HelloSoapBindingStub

    implements

    HelloWorld

    getHello()

    1. Make an instance of this

    Call methods on this proxy object

    2. Use it to make an instance of t

    e o or en rom u s

  • 8/14/2019 SENGER 060504 Web Services

    26/36

    public class HelloWorldClientFromStubs {public static void main (String [] args) {

    try {// prepare the calls (the same for all called methods)hello.generated.HelloWorldService service =new hello.generated.HelloWorldServiceLocator();

    hello.generated.HelloWorld myHelloProxy = service.getHello();

    // call "get message"if (args.length == 0) {

    String result = myHelloProxy.getHelloMessage()System.out.println (result);System.exit (0);

    }

    // call "set message" and afterwards "get messagemyHelloProxy.setHelloMessage (args[0]);System.out.println (myHelloProxy.getHelloMessage());

    } catch (Exception e) {System.err.println ("ERROR:\n" + e.toString());

    }}

    }

    e o or en rom u s.java

  • 8/14/2019 SENGER 060504 Web Services

    27/36

    Java XML DataJava XML Data

    MappingMapping How Java objects are convertedHow Java objects are converted

    to/from XML data (in order to be ableto/from XML data (in order to be able

    to be put into SOAP messages)to be put into SOAP messages)

    Important especially for the non-Important especially for the non-

    basic data typesbasic data types

    Its easier if your non-basic dataIts easier if your non-basic data

    types are Java Beans (havingtypes are Java Beans (having setset//getgetmethods for members)methods for members)

    A We erv ce examp ee erv ce examp e

  • 8/14/2019 SENGER 060504 Web Services

    28/36

    A We erv ce examp ee erv ce examp ein Perlin Perl

    This is a module implementingthe business logic

    package HelloPerl;use strict;use vars qw( $Message );

    $Message = 'Hello, here is Perl.';sub getHelloMessage { $Message; }sub setHelloMessage { $Message = shift; }1;

    This is a cgi-bin

    script

    #!/usr/bin/perl -w -- Perl

    use SOAP::Transport::HTTP;SOAP::Transport::HTTP::CGI

    -> dispatch_to('HelloPerl')-> handle;

    #!/usr/bin/perl wuse SOAP::Lite

    on_fault => sub {};print SOAP::Lite

    -> uri ('HelloPerl')-> proxy ('http://localhost/cgi-bin/helloserver.cgi')-> getHelloMessage

    -> result;

    This is a client

  • 8/14/2019 SENGER 060504 Web Services

    29/36

    SOAP::LiteSOAP::Lite

    a collection of (many) modulesa collection of (many) modules but they are loaded automatically when neededbut they are loaded automatically when needed

    supports SOAP 1.1 specificationsupports SOAP 1.1 specification

    all methods can be used for both settingall methods can be used for both setting

    and retrieving values:and retrieving values: if you provide no parameters, you will get current value,if you provide no parameters, you will get current value,

    and if parameters are provided, a new value will beand if parameters are provided, a new value will be

    assigned to the objectassigned to the object

    and the method in question will return the current objectand the method in question will return the current object

    (if not stated otherwise) which is is suitable for stacking(if not stated otherwise) which is is suitable for stackingthese calls like:these calls like:

    $lite = SOAP::Lite$lite = SOAP::Lite

    -> uri(openBQS')-> uri(openBQS')

    -> proxy('http://industry.ebi.ac.uk/soap/openBQS')-> proxy('http://industry.ebi.ac.uk/soap/openBQS')

    ;;

  • 8/14/2019 SENGER 060504 Web Services

    30/36

    Using wsdl - directlyUsing wsdl - directly

    #!/usr/bin/perl -w

    use SOAP::Lite on_fault => sub {};print SOAP::Lite

    -> service ('file:/home/senger/ws-ws/perl/Hello.wsdl')-> setHelloMessage (123);

    getting .wsdl file by using its URL then, you do not need to worry about

    autotyping

    #!/usr/bin/perl -w

    use SOAP::Lite on_fault => sub {};my $service = SOAP::Lite -> service ('file:./Hello.wsdl');$service->setHelloMessage ($ARGV[0] or "Hello!!!");print $service->getHelloMessage, "\n";

    W y to use Wey to use e

  • 8/14/2019 SENGER 060504 Web Services

    31/36

    W y to use Wey to use eServicesServices

    (comparing to CORBA)(comparing to CORBA) WS are easier to deploy because ofWS are easier to deploy because of

    their firewall-friendlinesstheir firewall-friendliness

    WS are quite well marketed (bothWS are quite well marketed (both

    from IT companies and Open Sourcefrom IT companies and Open Sourceprojects)projects)

    However:However:

    user sessions are less standardiseduser sessions are less standardised many parts yet-to-be-done (notification,many parts yet-to-be-done (notification,

    transactions, security, etc.)transactions, security, etc.)

    The programming effort andThe programming effort and

  • 8/14/2019 SENGER 060504 Web Services

    32/36

    1. What is similar1. What is similar

    The programming effort andThe programming effort andmaintainability is roughly the samemaintainability is roughly the sameboth for Web Services and CORBAboth for Web Services and CORBA

    For CORBA I need an ORBFor CORBA I need an ORB but do you know anybody doing WS withoutbut do you know anybody doing WS without

    a SOAP toolkit?a SOAP toolkit?

    For CORBA I need an IDL compilerFor CORBA I need an IDL compiler

    not always (ask Perl folks)not always (ask Perl folks) for WS you use frequently stubs generatedfor WS you use frequently stubs generated

    from WSDLfrom WSDL

    similar answers for valuetype/customsimilar answers for valuetype/custom

    encoding, etc.encoding, etc.

  • 8/14/2019 SENGER 060504 Web Services

    33/36

    2. What is2. What is (IMHO)(IMHO) betterbetter

    WS are easier to deploy because ofWS are easier to deploy because of

    their firewall-friendlinesstheir firewall-friendliness

    WS are quite well marketed (bothWS are quite well marketed (both

    from IT companies and Open Sourcefrom IT companies and Open Source

    projects)projects)

    Integration of WS into workflowsIntegration of WS into workflows

    seems to be very dynamic and veryseems to be very dynamic and very

    real topicreal topic

    comparing with CORBA Componentscomparing with CORBA Components

  • 8/14/2019 SENGER 060504 Web Services

    34/36

    3. What is3. What is (IMHO)(IMHO) worseworse

    Peer-to-peer access is problematicPeer-to-peer access is problematic

    notification by server-push is harder tonotification by server-push is harder to

    achieveachieve

    User sessions (servers state-User sessions (servers state-

    fullness) are less standardisedfullness) are less standardised

    and therefore less inter-operableand therefore less inter-operable

    Many parts yet-to-be-done, or theyMany parts yet-to-be-done, or they

    are quite complex (notification,are quite complex (notification,

    transactions, security, etc.)transactions, security, etc.)

  • 8/14/2019 SENGER 060504 Web Services

    35/36

    So what?So what?

    Don't throw the baby out with theDon't throw the baby out with the

    bathwaterbathwater

    combine the existing projects with acombine the existing projects with a

    new Web Services layer; in most cases itnew Web Services layer; in most cases itis not so difficultis not so difficult

    Apply existing standards to new WebApply existing standards to new Web

    Services projectsServices projects think MDA it may help, even withoutthink MDA it may help, even without

    the whole OMG adoption processthe whole OMG adoption process

  • 8/14/2019 SENGER 060504 Web Services

    36/36

    ConclusionsConclusions

    Distributed computing is inevitableDistributed computing is inevitable

    More accesses by programs than byMore accesses by programs than byclicking on hyperlinksclicking on hyperlinks

    More technologies of distributedMore technologies of distributedarchitecture will collaboratearchitecture will collaborate

    The better standards we have theThe better standards we have the

    better results well getbetter results well get Web Services is not a new hype but aWeb Services is not a new hype but a

    trend to followtrend to follow