Saturday 17 September 2011

CREATION OF WEB SERVICE CLIENT


CREATION OF WEB SERVICE CLIENT

Aim:
To create a web service for adding few numbers using NetBeans and write client side code to invoke the web service.

Algorithm:
Using the Netbeans API create a project of the type web application.
Create a web service in the project.
Click on the Design tab and design the prototype of the web service.
Click on source tab and modify the application logic of the web service.
Save the project.
Right click on the project and click on deploy and undeploy.
Then test the web service.
Create another web application project and create a jsp file.
Right click on project and click on create web service client.
Browse and choose the web service created i.e wsdl url
Drag and drop the web service reference to the source code window.
Then pass the appropriate parameters to the web service client and invoke the web service.

STEPS TO CREATE CLIENT SIDE PROJECT:
1.create the new project as above and give the name as addclient.
2. addclient project will be created. right click it and choose the following.
3.Then browse and choose the addweb wsdl file
4.Then choose the following and add the source code in index.jsp and save it.
Index.jsp source code
<%@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>
        <form name="" action="actionn.jsp" method="post">
 Enter 1st No:<input  name="fst" type="text" /><br/>
Enter 2nd No:<input  name="snd" type="text" /><br/>
 <input  name="ok" type="submit" value="Add" />
</form>
    </body>
</html>
5.Then create an action.jsp as follows.
Right click web page in addclient and choose new->jsp
Name:action
Click finish
6.click on the actionn.jsp  page..then right click in it and choose web service client reference ->call web service
7.The invoke the add service.
8. add the following code in the action.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>
         <%
 String a1=request.getParameter("fst");
String b1=request.getParameter("snd");
int aa=Integer.parseInt(a1);
int bb=Integer.parseInt(b1);
  %>      
    <%-- start web service invocation --%><hr/>
    <%
    try {
org.AddwebService service = new org.AddwebService();
org.Addweb port = service.getAddwebPort();
// TODO initialize WS operation arguments here
int a = aa;
int b = bb;
// TODO process result here
int result = port.add(a, b);
out.println("Result = "+result);
    } catch (Exception ex) {
// TODO handle custom exceptions here
    }
    %>
    <%-- end web service invocation --%><hr/>
    </body>
</html>
8.finally undeploy and deploy the addclient and run it.

0 comments:

Post a Comment