You are on page 1of 14

IMPLEMENTATION OF WEBSERVICES Ex.

No:
DATE: AIM: To write a simple web application program in Java to implement web services. THEORY: Web services constitute a distributed computer architecture made up of many different computers trying to communicate over the network to form one system. They consist of a set of standards that allow developers to implement distributed applications - using radically different tools provided by many different vendors - to create applications that use a combination of software modules called from systems in disparate departments or from other companies. A Web service contains some number of classes, interfaces, enumerations and structures that provide black box functionality to remote clients. Web services typically define business objects that execute a unit of work (e.g., perform a calculation, read a data source, etc.) for the consumer and wait for the next request. Web service consumer does not necessarily need to be a browser-based client. Console-baed and Windows Forms-based clients can consume a Web service. In each case, the client indirectly interacts with the Web service through an intervening proxy. The proxy looks and feels like the real remote type and exposes the same set of methods. Under the hood, the proxy code really forwards the request to the Web service using standard HTTP or optionally SOAP messages. WEB SERVICE STANDARDS Web services are registered and announced using the following services and protocols. Many of these and other standards are being worked out by the UDDI project, a group of industry leaders that is spearheading the early creation and design efforts. Universal Description, Discovery, and Integration (UDDI) is a protocol for describing available Web services components. This standard allows businesses to register with an Internet directory that will help them advertise their services, so companies can find one another and conduct transactions over the Web. This registration and lookup task is done using XML and HTTP(S)-based mechanisms. Simple Object Access Protocol (SOAP) is a protocol for initiating conversations with a UDDI Service. SOAP makes object access simple by allowing applications to invoke object methods or functions, residing on remote servers. A SOAP application creates a request block in XML, supplying the data needed by the remote method as well as the location of the remote object itself.

Web Service Description Language (WSDL), the proposed standard for how a Web service is described, is an XML-based service IDL (Interface Definitition Language) that defines the service interface and its implementation characteristics. WSDL is referenced by UDDI entries and describes the SOAP messages that define a particular Web service. ebXML (e-business XML) defines core components, business processes, registry and repository, messaging services, trading partner agreements, and security. IMPLEMENTING WEB SERVICES Here comes a brief step-by-step on how a Web service is implemented.

A service provider creates a Web service The service provider uses WSDL to describe the service to a UDDI registry The service provider registers the service in a UDDI registry and/or ebXML registry/repository. Another service or consumer locates and requests the registered service by querying UDDI and/or ebXML registries. The requesting service or user writes an application to bind the registered service using SOAP in the case of UDDI and/or ebXML Data and messages are exchanged as XML over HTTP

WEB SERVICES TECHNOLOGIES AND TOOLS There are a number of mechanisms for constructing Web services. Microsoft has come out with a new object-oriented language C# as the development language for Web services and .NET framework. Microsoft has an exciting tool called Visual Studio .NET in this regard. The back end database can be Microsoft SQL Server 2000 in Windows 2000 Professional. Sun Microsystems has its own set of technologies and tools for facilitating Web services development. Java Servlets, Java Server Pages (JSPs), Enterprise JavaBeans (EJB) architecture and other Java 2 Enterprise Edition (J2EE) technologies play a very critical role in developing Web services. There are a number of tools for developing Web services. They are Forte Java IDE, Oracle JDeveloper, and WebGain Studio. Sun Microsystems has taken an initiative called Sun ONE (Open Network Environment) and is planning to push Java forward as a platform for Web services. It is developing Java APIs for XML-based remote procedure calls and for looking up services in XML registries - two more JAX family APIs: JAX/RPC (Java API for XML Remote Procedure Calls) and JAXR (Java API for XML Registries). These will wrap up implementations of Web services standards, such as SOAP and UDDI.

IBM also for its part has already developed a suite of early-access tools for Web services development. They are Web Services Toolkit (WSTK), WSDL Toolkit, and Web Services Development Environment (WSDE).

CODING:

index.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> </body> </html> MyWebService.java package pack1; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class MyWebService { @WebMethod(operationName = "show") public String show(@WebParam(name = "name") String name) { return "hello"+name; } } client.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <%-- start web service invocation --%><hr/> <% try { pack1.MyWebServiceService service = new pack1.MyWebServiceService(); pack1.MyWebService port = service.getMyWebServicePort(); java.lang.String name = "sha"; java.lang.String result = port.show(name); out.println("Result = "+result); } catch (Exception ex) {} %> <%-- end web service invocation --%><hr/> </body> </html> MyWebService.wsdl Generated file <?xml version="1.0" encoding="UTF-8"?> <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-utility-1.0.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://pack1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://pack1/" name="MyWebServiceService"> <types> <xsd:schema> <xsd:import namespace="http://pack1/" schemaLocation="http://localhost:8080/webservice7/MyWebServiceService? xsd=1"></xsd:import> </xsd:schema> </types> <message name="show"> <part name="parameters" element="tns:show"></part> </message> <message name="showResponse"> <part name="parameters" element="tns:showResponse"></part> </message> <portType name="MyWebService"> <operation name="show"> <input message="tns:show"></input> <output message="tns:showResponse"></output> </operation> </portType> <binding name="MyWebServicePortBinding" type="tns:MyWebService"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding> <operation name="show"> <soap:operation soapAction=""></soap:operation> <input>

<soap:body use="literal"></soap:body> </input> <output> <soap:body use="literal"></soap:body> </output> </operation> </binding> <service name="MyWebServiceService"> <port name="MyWebServicePort" binding="tns:MyWebServicePortBinding"> <soap:address location="http://localhost:8080/webservice7/MyWebServiceService"></soap:address> </port> </service> </definitions> MyWebService.xsd Generated file <?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI at http://jaxws.dev.java.net. RI's version is JAX-WS RI 2.1.3.1-hudson-749-SNAPSHOT. --><xs:schema xmlns:tns="http://pack1/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://pack1/"> <xs:element name="show" type="tns:show"></xs:element> <xs:element name="showResponse" type="tns:showResponse"></xs:element> <xs:complexType name="show"> <xs:sequence> <xs:element name="name" type="xs:string" minOccurs="0"></xs:element> </xs:sequence> </xs:complexType>

<xs:complexType name="showResponse"> <xs:sequence> <xs:element name="return" type="xs:string" minOccurs="0"></xs:element> </xs:sequence> </xs:complexType> </xs:schema> SOAP Request Generated file <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header/> <S:Body> <ns2:show xmlns:ns2="http://pack1/"> <name>sha</name> </ns2:show> </S:Body> </S:Envelope> SOAP Response Generated file <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <ns2:showResponse xmlns:ns2="http://pack1/"> <return>hellosha</return> </ns2:showResponse> </S:Body> </S:Envelope>

SCREEN SHOTS:

OUTPUT:

RESULT: Thus a simple web application program is converted into web services.

You might also like