0% found this document useful (0 votes)
17 views

Web Service pr6

The document describes steps to create a client application that consumes services developed in different platforms: 1. Create an ASP.NET web application project in Visual Studio and add a web service that exposes methods to perform basic math operations like addition, subtraction, multiplication and division. 2. Generate a web service client in NetBeans by adding the web service WSDL URL. 3. Create JSP files with code to call the web service operations and display results by passing values submitted from an HTML form. 4. Run the project in NetBeans to test consuming the web service from the client application.

Uploaded by

vaibhav gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Web Service pr6

The document describes steps to create a client application that consumes services developed in different platforms: 1. Create an ASP.NET web application project in Visual Studio and add a web service that exposes methods to perform basic math operations like addition, subtraction, multiplication and division. 2. Generate a web service client in NetBeans by adding the web service WSDL URL. 3. Create JSP files with code to call the web service operations and display results by passing values submitted from an HTML form. 4. Run the project in NetBeans to test consuming the web service from the client application.

Uploaded by

vaibhav gaikwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Practical no.

6:
~Made by Shlok Punekar

Develop a Client Application that consumes services developed in


different platforms.
Steps:
Open Visual Studio 2019

Create a new project

Select ASP.NET Web Application (.NET Framework)


Give project name and create
Select Empty, uncheck Configure for HTTPS, and create
Right Cick on project > Add > New Item

Search web service, select it and add


Add the above source code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Webservice
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment
the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{

[WebMethod]
public double add(double a, double b)
{
return a + b;
}

[WebMethod]
public double subtract(double a, double b)
{
return a - b;
}

[WebMethod]
public double multiply(double a, double b)
{
return a * b;
}

[WebMethod]
public double divide(double a, double b)
{
return a / b;
}

}
}

Output:
Click on Service Description url

The above xml file will appear, copy it’s url


Open Netbeans

Createa new project


Give Project Name
Finish
Right click on project > new > web service client

Select WSDL URL and paste the copied url of XML file in it, give package name and finish
Web Service Client added
Create a new jsp file

Give file name and finish


On the jsp file, right click anywhere> web service client resources > call web service operation
Select add operation and click OK
Same way add all the operations.

Source Code:

Index.html:

<!DOCTYPE html>

<!--

To change this license header, choose License Headers in Project Properties.

To change this template file, choose Tools | Templates

and open the template in the editor.

-->

<html>

<head>

<title>TODO supply a title</title>


<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>

<body>

<form action="Operations.jsp" method="post" >

Num1<input type="text" name="n1"><br><br>

Num2<input type="text" name="n2"><br><br>

<input type="submit" value="Perform Operations">

</form>

</body>

</html>

Operations.jsp:

<%--

Document : Operations

Created on : Aug 17, 2023, 11:50:51 AM

Author : student

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<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/>

<%

double a = Integer.parseInt(request.getParameter("n1"));

double b = Integer.parseInt(request.getParameter("n2"));

try {

com.dd.WebService1 service = new com.dd.WebService1();

com.dd.WebService1Soap port = service.getWebService1Soap();

// TODO initialize WS operati

// TODO process result here

double result = port.add(a, b);

out.println("Result = "+result);

} catch (Exception ex) {

// TODO handle custom exceptions here

%>

<%-- end web service invocation --%><hr/>

<%-- start web service invocation --%><hr/>

<%

try {

com.dd.WebService1 service = new com.dd.WebService1();

com.dd.WebService1Soap port = service.getWebService1Soap();

// TODO process result here

double result = port.divide(a, b);

out.println("Result = "+result);

} catch (Exception ex) {

// TODO handle custom exceptions here

}
%>

<%-- end web service invocation --%><hr/>

<%-- start web service invocation --%><hr/>

<%

try {

com.dd.WebService1 service = new com.dd.WebService1();

com.dd.WebService1Soap port = service.getWebService1Soap();

// TODO process result here

double result = port.multiply(a, b);

out.println("Result = "+result);

} catch (Exception ex) {

// TODO handle custom exceptions here

%>

<%-- end web service invocation --%><hr/>

<%-- start web service invocation --%><hr/>

<%

try {

com.dd.WebService1 service = new com.dd.WebService1();

com.dd.WebService1Soap port = service.getWebService1Soap();

// TODO process result here

double result = port.subtract(a, b);

out.println("Result = "+result);

} catch (Exception ex) {

// TODO handle custom exceptions here

%>
<%-- end web service invocation --%><hr/>

</body>

</html>

Finally, Run the project in netbeans

Output:

You might also like