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

Creating A Web Service Using Asp

The document describes how to create a web service using ASP.NET that performs basic arithmetic operations. It involves creating a web application project, adding a web service item, and writing code within the service to calculate results based on inputs and operators. A client website is then created, the web service is referenced, and code is added to call the calculation method and display results. When run, the client application can now access and use the arithmetic operations provided by the web service.

Uploaded by

Amalraj Victoire
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Creating A Web Service Using Asp

The document describes how to create a web service using ASP.NET that performs basic arithmetic operations. It involves creating a web application project, adding a web service item, and writing code within the service to calculate results based on inputs and operators. A client website is then created, the web service is referenced, and code is added to call the calculation method and display results. When run, the client application can now access and use the arithmetic operations provided by the web service.

Uploaded by

Amalraj Victoire
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Creating a web service using asp.

net client and server

 To create a web service :


o Create a project by using file -> new -> project

o Create a web application by using web -> asp.net web application under .net
framework 4
o In the solution explorer right click the file name -> Add -> New Item -> web
service
o In the file created include the code for performing basic arithmetic operations
within the class

[WebMethod]
public string calculate(string first, string second, char
sign)
{
string result;
switch (sign)
{
case '+':
{
result = (Convert.ToInt32(first) +
Convert.ToInt32(second)).ToString();
break;
}
case '-':
{
result = (Convert.ToInt32(first) -
Convert.ToInt32(second)).ToString();
break;
}
case '*':
{
result = (Convert.ToInt32(first) *
Convert.ToInt32(second)).ToString();
break;
}
case '/':
{
result = (Convert.ToInt32(first) /
Convert.ToInt32(second)).ToString();
break;
}
case '%':
{
result = (Convert.ToInt32(first) %
Convert.ToInt32(second)).ToString();
break;
}
default:
result = "Invalid";
break;
}
return result;
}
 By doing this a service is created

 Now create a client to use the service create a website by the file -> new -> website
 Add the service reference to the created website by right clicking the website name in
the solution explorer ->

 You will get the following screen


 Add the service by running the web service created before and copy the url

 Paste the url in the add service dialog box in the address textbox and click go
 Then you get the notification as service is running name the namespace and click OK

 Now design the default.aspx page


 Double click the button to write the action code for the button and insert the following
snippet in the default.aspx.cs file

protected void Button1_Click(object sender, EventArgs e)


{
String a = TextBox1.Text;
String b = TextBox2.Text;
char c = Convert.ToChar(TextBox3.Text);
TextBox4.Text = ws.calculate(a, b, c);
}
 Create a object for the added service namespace

Test.WebService1SoapClient ws = new
Test.WebService1SoapClient();
 Run the web application for getting the output

You might also like