8/4/2019 SOA Ex 1 & Ex2
1/18
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 NewWeb 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
Date:
8/4/2019 SOA Ex 1 & Ex2
2/18
CREATION OF SERVICE FOR FACTORIAL CALCULATION
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
8/4/2019 SOA Ex 1 & Ex2
3/18
OUTPUT:
8/4/2019 SOA Ex 1 & Ex2
4/18
8/4/2019 SOA Ex 1 & Ex2
5/18
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;}
}
Ex No.: 1 (b)
Date:
8/4/2019 SOA Ex 1 & Ex2
6/18
8/4/2019 SOA Ex 1 & Ex2
7/18
8/4/2019 SOA Ex 1 & Ex2
8/18
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)
Ex No.: 1 (c)
Date:
8/4/2019 SOA Ex 1 & Ex2
9/18
bal=4000-price;
else
bal=0;return bal;
}
}
8/4/2019 SOA Ex 1 & Ex2
10/18
OUTPUT:
8/4/2019 SOA Ex 1 & Ex2
11/18
RESULT:
Thus, the web services have been invoked successfully for calculator program, factorial
calculation and payment processing on the server side.
8/4/2019 SOA Ex 1 & Ex2
12/18
CLIENT INVOKING OF WEB SERVICES IN NET BEANS IDE
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 NewWeb 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.
Ex No.: 2
Date:
8/4/2019 SOA Ex 1 & Ex2
13/18
INVOKING FACTORIAL SERVICE USING .NET COMPONENT
PROGRAM:
factorial.jsp
JSP Page
Hello World!
Ex No.: 2 (a)
Date:
8/4/2019 SOA Ex 1 & Ex2
14/18
OUTPUT:
8/4/2019 SOA Ex 1 & Ex2
15/18
INVOKING CALCULATOR SERVICE USING .NET
COMPONENT
PROGRAM:
calculator.jsp
JSP Page
Hello World!
Ex No.: 2 (b)
Date:
8/4/2019 SOA Ex 1 & Ex2
16/18
OUTPUT:
8/4/2019 SOA Ex 1 & Ex2
17/18
INVOKING SIMPLE ORDER PAYMENT SERVICE USING
.NET COMPONENT
PROGRAM:
payment.jsp
JSP Page
Hello World!
Ex No.: 2 (c)
Date:
8/4/2019 SOA Ex 1 & Ex2
18/18
OUTPUT:
RESULT:
Thus,the web services has been invoked successfully for calculator program,factorial
calculation and payment processing on the client side.