Web Services 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Name: - Roll No:- Class: - TYCS

Subject: - Web Services Practical no:-04 Date: -

Aim:- Develop client which consumes web services developed in different platforms.
Requirement:-

1. Visual studio 2010

2. Netbeans 8.2

In this practical we are creating Web Service in Visual Studio and then we will consume it in NetBeans.

1. Open Visual Studio IDE and click on File.


File -> New ->Project
2. Click on Web.
Web -> ASP.NET Web Application and give Name as Service.
After that click OK button.

3. Now you can see, on the right side in Solution Explorer ->Service project is created.
4. Right click on Service->Add->New Item.

5. Search for Web Service. And give Name as Operation.


Then click on Add button.
6. After click on Add button, Operation.asmx.cs file will be automatically open.
Then add the following code into class Operation.

[WebMethod]
public double Add(double a, double b)
{
double sum = a + b;
return sum;
}
[WebMethod]
public double Mult(double a, double b)
{
double sum = a * b;
return sum;
}

After that press Ctrl+s to save the methods. We are creating two methods foe Web
Service.one for addition of two numbers and second for multiplication of two numbers.
7. Now Run the Project by clicking on Green arrow below the windows menu.

8. A window will open in browser and that is our web service.

9. You can check services by clicking on Add or Mult option. But we don’t need this.

10. Now click on Service Description option.


11. A new window will open. Select the link and copy it. we will use this in Netbeans to
consume these services.

12. Don’t close the visual studio and browser, just minimize it else server will stop.

13. Open NetBeans.

14. Create a Web Application with name SeviceClient. Next->Finish.


15. Now create a Web Service Client.
Right click on ServiceClient -> New -> Other.

16. Now select WebServices in Categories section.


WebServices -> Web service Client and click Next button.
17. Select WSDL URL and paste the Link that you have copied from browser on run of
Visual Studio. Enter package name as com.dd . After that click on Finish button.

18. We can see that, we have got both the service methods i.e Add & Mult. Select atmost
one method.
19. Now create a JSP page. Right click on ServiceClient -> New -> Other.

20. Select Web in Categories section -> Select JSP and click on Next button.
21. Enter File Name ‘Add’ and click on Finish button.

22. In Add.jsp file delete the content in body tag.

23. Right click between body tag and select Call Web Service Operation.
24. Expand and select Add. After select, click on OK button.

25. Now add the following code outside of try block.


double num1=Double.parseDouble(request.getParameter("txt1"));
double num2=Double.parseDouble(request.getParameter("txt2"));
26. Now pass num1 & num2 to a & b variable respectively .After that save the code.

27. Now open index.html file of ServiceClient project and replace the contents of body tag with
following code. Then save the code.
<form>
<input type="text" name="txt1" placeholder="Enter First Number:"><br><br>
<input type="text" name="txt2" placeholder="Enter Second Number:"><br><br>
<input type="submit" formaction="Add.jsp" value="Add numbers">
</form>

28. Now run the ServerClient web application.

A window will open in browser as

below.
29. Now enter two numbers and click on Add Numbers button.

30. You will get result on a new page.

You might also like