SIGN UP MEMBER LOGIN:    
ARTICLE

Creating and Consuming Web Service

Posted by Alok Pandey Articles | Web Services in C# November 19, 2011
In this article, you will learn a simple way to create a web service and use the service in a web application.
Reader Level:

Introduction: 

This article describes a simple way to create web services and use services in web applications. I have created a simple web service which returns a string message. In my web application, I have taken a Button which show the message from service on click event. Follow given steps for doing this.

Step 1: Open Visual Studio 2010 and create  a new web site.->Select .Net Framework 3.5. ->Select ASP.NET Web Service page -> Then, you have to give the name of your service. In this example I am giving it's name "mywebservice". Then Click the ok Button. A screen-shot of these activity is given below.

creating web services

Step 2: A code window will open after Clicking the Ok Button which is given below.

creating web services
 
Here (In the above figure), you will note that there is predefined method "HelloWorld" which returns the string "Hello World". You can use your own method and can perform different operation. Here, I am only describing the process for creating web services so I am using the same.

Step 3: Run this application. 

creating web services

Step 4: Now take a new web site to consume web service. For doing this, take a ASP.NET Empty Web Site, give it a name and Click the ok Button. 

creating web services

Step 5: Add New Item and select web form then click the Add Button. Now right click at your project in Solution Explorer. After doing this a pop - up menu will be appeared. -> select Add Web Reference.

creating web services

Step 6: After clicking on Add Web Reference, a new window is appeared:

creating web services

Step 7: Copy the URL of your web service application (Which is mywebservice in my example) and paste to it at place of URL and Click the (Go) Button.

creating web services

Step 8: Click the Add Reference Button. Now reference has been added to your application.

creating web services

Now, write the code. I am simply adding a Button control on design window of web page. Write the following code on Button Click event. This code is written for showing the output on the window screen.

creating web services

Step 9: Run the web application.

Output:

creating web services

Now Click the Ok Button. The string "Hello World" is displayed at screen which is defined in HelloWorld method of Service.

Output:

creating web services

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks, Divya.

Posted by Alok Pandey Jan 30, 2012

wonderful

Posted by divya ganesh Jan 28, 2012

Thanks,selva.

Posted by Alok Pandey Dec 01, 2011

nice..

Posted by selva raju Dec 01, 2011

Thank you sir.

Posted by Alok Pandey Nov 28, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor