lesson14-vt09

Upload: anjali-gaikwad

Post on 05-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 lesson14-vt09

    1/10

    3 March 2009 1

    Web Services.

    What is a Web Service?

    It is an application component that can be accessed using

    Web protocols and data encoding mechanisms such as

    HTTP and XML.

    In our context the application is housed inside a web con-

    tainer.

    It is accessed using the HTTP protocol but we dont use a

    browser.

  • 7/31/2019 lesson14-vt09

    2/10

    3 March 2009 2

    Web Service Technologies and Protocols

    The following standards and protocols are stand-

    ards in Web Services The Simple Object Access Protocol, SOAP, com-

    bines XML and MIME to create an extensible pack-aging format.

    The Web Services Description Language, WSDL isan XML vocabulary to describe Web Services.

    Universal Description, Discovery, and Integration(UDDI) provides a model for organizing, register-ing and accessing information about Web Services.

    The Web Service Flow Language (WSFL) and WebService Collaboration Language (WSCL) are con-cerned with describing the workflow between

    services so relationships can be encapsulated aspart of an application

    Electronic Business XML (ebXML) provides aframework for e-Commerce.

  • 7/31/2019 lesson14-vt09

    3/10

    3 March 2009 3

    SOAP can be carried over different protocols but in aJavaEE environment we often use HTTP. A messagecontains XML-documents wrapped in an XML

    SOAP envelope that forms the body of an HTTPPOST request.

    A SOAP message describes how the service invoka-tion should be done. One way is to use RPC styleinvokation.

    How to do this is descibed in JAX-WS, the Java APIfor XML Web services.

    To handle JAX-WS on the server-side, you need apiece of code that unpacks and parses the SOAPmessages. It also invokes the service.

  • 7/31/2019 lesson14-vt09

    4/10

    3 March 2009 4

    Technically JAX-WS works similar to RMI, i. e. usesinterfaces as proxies for the real service.

    We use WSDL to describe our service and to gener-ate the stubs and interfaces that are needed.

  • 7/31/2019 lesson14-vt09

    5/10

    3 March 2009 5

    Web Service Architecture

    WSDLinterfaces

    SOAPRPC

    client

    JavaEE server

    Serv-ice

    End pointservice

  • 7/31/2019 lesson14-vt09

    6/10

    3 March 2009 6

    To build a service you need to:

    Write a Service Endpoint interface and implementit.

    Compile the Java files

    Run the wsgen tool to produce the files needed fordeployment

    package this into a WAR-file.

    deploy the web service.

    write the client

    use wsimport to generate things that are needed toconnect to the service

    compile the client

    package the client and run it.

  • 7/31/2019 lesson14-vt09

    7/10

    3 March 2009 7

    An example of a web service is:

    package helloservice.endpoint;

    import javax.jws.WebMethod;import javax.jws.WebService;

    @WebService

    public class Hello {private String message = new String(Hello, );

    @WebMethodpublic String sayHello(String name) {

    return message + name + .;}

    }

  • 7/31/2019 lesson14-vt09

    8/10

    3 March 2009 8

    Our client

    package simpleclient;

    import javax.xml.ws.WebServiceRef;import helloservice.endpoint.HelloService;import helloservice.endpoint.Hello;

    public class HelloClient {@WebServiceRef(wsdlLocation =

    http://localhost:8080/helloservice/hello?wsdl)static HelloService service;

    /*** @param args the command line arguments*/

    public static void main(String[] args) {try {

    HelloClient client = new HelloClient();client.doTest(args);

    } catch (Exception ex) {ex.printStackTrace();

    }}

    public void doTest(String[] args) {try { // Call Web Service Operation

    System.out.println(Retrieving the port from the following

    service: + service);

  • 7/31/2019 lesson14-vt09

    9/10

    3 March 2009 9

    Hello port = service.getHelloPort();

    System.out.println(Invoking the sayHello operation on theport.);

    String name;

    if (args.length > 0) {

    name = args[0];} else {name = No Name;

    }

    String response = port.sayHello(name);System.out.println(response);

    } catch (Exception ex) {ex.printStackTrace();}

    }}

  • 7/31/2019 lesson14-vt09

    10/10

    3 March 2009 10

    We can now deploy the webservice and run the cli-ent as a normal java program.