Documentos de Académico
Documentos de Profesional
Documentos de Cultura
: 1 Date:
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; } }
OUTPUT:
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:
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)
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
OUTPUT:
OUTPUT:
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.