Thursday, October 20, 2011

Web Service


Web Services platform elements :-

XML is used to tag the data.
SOAP is used to transfer the data.
WSDL is used for describing the services available.
UDDI is used for listing what services are available.

-------------------------------------------------------------------
How to create the Web services 


Server creation
  1. Create a project in Workspace
  2. Create a java class with method which can be exposed as a web service.
  3. Expose this java class as a web service
  4. select create web service 
  5. select test web services
  6. select finish button
after this 
Click on finish - > this will generate WSDL file for your web service under Web content -> wsdl folder.


web service client :-

1. copy the wsdl file in web-inf/wsdl folder 
2. Right click on wsdl file and select webservice for webservice client creation 
3. Below java file will creating 
        Hello.java HelloService.java HelloServiceInformation.java HelloServiceLocator.java HelloSoapBuindigStub.java


if u want to call web services in jsp page below is code 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.net.*,org.ibm.*" %>
<html>
<head>
<title>index</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<%

  HelloService service = new HelloServiceLocator();

    Hello req = service.getHello(new URL("http://localhost:9081/WebSerAppServer/services/Hello" ));
   
    out.println(req.getMessage(" I am in JSP "));

%>
</body>
</html>