Creating A Web Service Using Asp
Creating A Web Service Using Asp
Creating A Web Service Using Asp
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 ->
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
Test.WebService1SoapClient ws = new
Test.WebService1SoapClient();
Run the web application for getting the output