Está en la página 1de 18

Ex No.

: 1 Date:

SERVER CREATION FOR WEB SERVICES IN NET BEANS IDE


AIM: To design a web service for the following applications on the server side. a.Calculator program b.Factorial calculation c.Payment Processing PROCEDURE: 1. Goto FileNew ProjectChoose Project (Java Web)then select Web Application click Next button 2. Give project name click next buttonclick next buttonclick next buttonfinish It will open the project window with index.jsp page 6. Goto Main Project Right Click the project select New Web Service specify the web service name (MyWebService) and include package name (pack1) click finish button 7. Goto Design View of the project click Addoperation it will show add operation window Add the operation one by one Click the button Add change the parameters with the corresponding functions then click ok button 8. Goto source view change the code editor window change return null to return the calculated value. And save the project (ctrl +S) 9. Goto main project right click the project select deploy (it will deploy the project in service registry) 10.Goto the folder Web Services select the created WebServiceright click select test web service. It will open MyWebServiceService Tester page give any value to do the operation Click buttons it will open the correspondingMethod Invocation.

Ex No.: 1 (a) Date: PROGRAM: //Fact.java package a; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class NewWebService { @WebMethod(operationName = "fact") public int fact(@WebParam(name = "n") int n) { int i,f=1; for(i=1;i<=n;i++) f=f*i; return f; } }

CREATION OF SERVICE FOR FACTORIAL CALCULATION

OUTPUT:

Ex No.: 1 (b) Date:

CREATION OF SERVICE FOR A CALCULATOR

PROGRAM: //Calc.java package a1; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class NewWebService { @WebMethod(operationName = "calc") public int calc(@WebParam(name = "choice") int choice, @WebParam(name = "a") int a, @WebParam(name = "b") int b) { int c; switch(choice) { case 1: c=a+b; return c; case 2: c=a-b; return c; case 3: c=a*b; return c; case 4: c=a/b; return c; default: break; } return 0; } }

OUTPUT:

Ex No.: 1 (c) Date:

CREATION OF SERVICE FOR A SIMPLE ORDER PAYMENT PROCESSING

PROGRAM: //Payment.java package p; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; @WebService() public class NewWebService { @WebMethod(operationName = "order") public int order(@WebParam(name = "a") int a, @WebParam(name = "b") int b, @WebParam(name = "num") long num) { int c,c1,bal,price; if(a==1) c=100; else if(a==2) c=150; else if(a==3) c=200; else if(a==4) c=250; else c=0; if(b==1) c1=100; else if(b==2) c1=150; else if(b==3) c1=200; else if(a==4) c1=250; else c1=0; price=c+c1; if(num==1234) bal=3000-price; else if(num==5678)

bal=4000-price; else bal=0; return bal; } }

OUTPUT:

RESULT: Thus, the web services have been invoked successfully for calculator program, factorial calculation and payment processing on the server side.

Ex No.: 2 Date: AIM: To design a web service for the following applications on the client side. a.Calculator program b.Factorial calculation c.Payment Processing PROCEDURE: 1. Goto FileNew ProjectChoose Project (Java Web)then select Web Application click Next button 2. Give Project Name click next button click next button click next buttonfinish 3. Goto Main Project Right Click the project select New Web Service Client click browse buttonselect the WSDL file of server side click ok button click finish button 4. Goto main project right click the application Select New JSP file specify JSP File name (client) click finish button 5. In client.jsp code editor window In body part of the code right click select Web Service Client Resources select Call Web Service Operation 6. It will open Select Operation to Invoke from that window select show operation click ok button 7. Change the code save the application 8. Goto client.jsp file right click select Run File it will execute the web service application. CLIENT INVOKING OF WEB SERVICES IN NET BEANS IDE

Ex No.: 2 (a) Date:

INVOKING FACTORIAL SERVICE USING .NET COMPONENT


PROGRAM: factorial.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 { e.NewWebService1Service service = new e.NewWebService1Service(); e.NewWebService1 port = service.getNewWebService1Port(); // TODO initialize WS operation arguments here int n = 5; // TODO process result here int result = port.fact(n); out.println("Result = "+result); } catch (Exception ex) { // TODO handle custom exceptions here } %> <%-- end web service invocation --%><hr/> </body> </html>

OUTPUT:

Ex No.: 2 (b) Date:

INVOKING CALCULATOR SERVICE USING .NET COMPONENT


PROGRAM: calculator.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 { a.NewWebServiceService service = new a.NewWebServiceService(); a.NewWebService port = service.getNewWebServicePort(); // TODO initialize WS operation arguments here int n = 1; int a = 2; int b = 3; // TODO process result here int result = port.choice(n, a, b); out.println("Result = "+result); } catch (Exception ex) { // TODO handle custom exceptions here } %> <%-- end web service invocation --%><hr/> </body> </html>

OUTPUT:

Ex No.: 2 (c) Date:

INVOKING SIMPLE ORDER PAYMENT SERVICE USING .NET COMPONENT

PROGRAM: payment.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 { p.NewWebServiceService service = new p.NewWebServiceService(); p.NewWebService port = service.getNewWebServicePort(); // TODO initialize WS operation arguments here int a = 1; int b = 2; long num = 1234; // TODO process result here int result = port.order(a, b, num); out.println("Result = "+result); } catch (Exception ex) { // TODO handle custom exceptions here } %> <%-- end web service invocation --%><hr/> </body> </html>

OUTPUT:

RESULT: Thus,the web services has been invoked successfully for calculator program,factorial calculation and payment processing on the client side.

También podría gustarte