This blog explains basic knowledge abut how to create and use web services.
Create WebService
- Open Visual Studio 2010
- Click on New project Link on start page
- New Project Window Will Open
- Select Asp.net Web Application in the template window
- Enter the name of project
- Click on ok button
- Open Solution Explorer of your project
- Right click on project, the pop window will open
- Drag cursor on to add menu, the submenu of add menu will open, click on NewItem or Go to Add->NewItem.
- The AddNew Item Window will open, Select WebService and Rename WebService1.asmx to MyWebService.asmx, then click on ok button.
- The MyWebService.asmx file will appear in the solution explorer, open MyWebService.asmx file
- Declare your own method in this file
bellow the HellowWorld function. You can remove the HellowWorld function
from the WebService.
For Example : the bellow function generate a random number and returns to it.
[WebMethod(Description = "Get Random Number")]//Description about web method
public string GetNumber() // Declaration of Method
{
Random RM=new Random();
return RM.Next(1,100).ToString();
}
[WebMethod(Description = "Adds Two Number And return result")]
public string Add(int firstno, int secondno)
{
double result = firstno + secondno;
return result.ToString();
}
This is the all about create web service in your project, and then we will discuss about how to use or consume web service in your application.
- Right click on your WebService i.e MyService.asmx and click on Browse With. The Browser with window will open, select your installed explorer, for example select Internet Explorer.
- Copy the URL adder from the URL of browser.
- Right click on your project, click AddServiceReference , the Service Reference Window will open.
- Past the copied URL address in the address textbox of service reference window. click to 'Go' button
- Rename the Namespace as required and then Press ok.
- The reference of the Webservice will be appear in the Service Reference folder in solution explorer.
- Go to the default page of your project, take one label, set the text to 'Random Number'.
- Take another label control set this text as '0' and id as 'lblRandom'.
- Take a button set the text to 'Get ' and
write the following code in the click event of the Button.
MyWebService.MyService MS = new MyService();
Label1.Text= MS.GetNumber();

bava palaniPosted Mar 19, 2019, 12:15 AM EDT
Hai.....that's amazing job.........thank you so much.....
chan chanPosted Oct 11, 2018, 10:15 PM EDT
Hi nice details provided. I am using .net3.5 in VS2012 and created simple web services and I am facing "HTTP Error 404.3 - Not Found" error while trying to open from IIS. I need to host it in IIS and access it from anywhere within the network, but I am unable to resolve. Could you please help me in resolving this issue, Please. My contact is [email protected]. just needs solutions for hosting a webservice in IIS. I have tried all possibilities
Vittorio MorelliniPosted May 23, 2016, 4:21 AM EDT
I have no need to create a multitasking web service, IIS will manage multitasking request on a web service. Asmx is the best way in VS2010 ?
Vittorio MorelliniPosted May 23, 2016, 4:19 AM EDT
Is this the Best way to create a Web Service multitasking ? via VS2010 ? or Web Api pattern is better ? is it available in VS2010 ?
JohnPosted Jan 15, 2016, 6:39 PM EST
I wanted to know how to send bulk data to web service using json
Muhammad Ashikuzzaman AshikPosted Oct 11, 2015, 4:34 AM EDT
Thank you very much. I was confused I was surmising that I may have to set up another .exe file to get web service like WCF in visual studio 2010.
Nahed DaberhaPosted Sep 10, 2015, 9:29 AM EDT
Thank you
kunedo kunedoPosted May 27, 2015, 1:27 PM EDT
Thanks you for the help
kushan fernandoPosted Mar 25, 2015, 4:30 AM EDT
Thank you for the simple and easy example.
Rich KeslarPosted Jan 23, 2015, 7:22 AM EST
Thanks, that was a good example. I was able to get it working.
Narasimhan RamaniPosted Sep 21, 2014, 11:26 PM EDT
Thanks
s vPosted Oct 30, 2013, 9:22 AM EDT
Thanks for this usefull tutorial