You are on page 1of 10

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 container. It is accessed using the HTTP protocol but we dont use a browser.

3 March 2009

Web Service Technologies and Protocols The following standards and protocols are standards in Web Services

The Simple Object Access Protocol, SOAP, combines XML and MIME to create an extensible packaging format. The Web Services Description Language, WSDL is an XML vocabulary to describe Web Services. Universal Description, Discovery, and Integration (UDDI) provides a model for organizing, registering and accessing information about Web Services. The Web Service Flow Language (WSFL) and Web Service Collaboration Language (WSCL) are concerned with describing the workow between services so relationships can be encapsulated as part of an application Electronic Business XML (ebXML) provides a framework for e-Commerce.

3 March 2009

SOAP can be carried over different protocols but in a JavaEE environment we often use HTTP. A message contains XML-documents wrapped in an XML SOAP envelope that forms the body of an HTTP POST request. A SOAP message describes how the service invokation should be done. One way is to use RPC style invokation. How to do this is descibed in JAX-WS, the Java API for XML Web services. To handle JAX-WS on the server-side, you need a piece of code that unpacks and parses the SOAP messages. It also invokes the service.

3 March 2009

Technically JAX-WS works similar to RMI, i. e. uses interfaces as proxies for the real service. We use WSDL to describe our service and to generate the stubs and interfaces that are needed.

3 March 2009

Web Service Architecture

WSDL interfaces SOAP RPC client JavaEE server End point service Service

3 March 2009

To build a service you need to:

Write a Service Endpoint interface and implement it. Compile the Java les Run the wsgen tool to produce the les needed for deployment package this into a WAR-le. deploy the web service. write the client use wsimport to generate things that are needed to connect to the service compile the client package the client and run it.

3 March 2009

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, ); @WebMethod public String sayHello(String name) { return message + name + .; } }

3 March 2009

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);
3 March 2009 8

Hello port = service.getHelloPort(); System.out.println( Invoking the sayHello operation on the port.); 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(); } } }

3 March 2009

We can now deploy the webservice and run the client as a normal java program.

3 March 2009

10

You might also like