Home > ASP.NET > Adding Web Service to Websites – Visual Studio 2010

Adding Web Service to Websites – Visual Studio 2010

File -> New -> Websites -> <name your website>

Go Solution Explorer

Right Button Solution  -> Add New Item -> Web Service -> <name your webservice>

Add a new WebMethod in webservice page as

[WebMethod]
public int Add(int a,int b)
{
return a + b;
}

Run this webservice and copy the url of this page from browser.

Select Menu  Website -> Add Service Reference

Paste the address in Address field and click Go

Edit the namespace.

Click OK

In Default.aspx.cs …

protected void Page_Load(object sender, EventArgs e)
{
YourServiceReferenceName.WebServiceSoapClient pp = new YourServiceReferenceName.WebServiceSoapClient();
int sum=pp.Add(6, 8);
Response.Write(sum);
}

Run Default.aspx

Advertisements
Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: