Now we will see how to create new web service application in asp.net
Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Service
Now our new web service ready our webservice website like this
Now open your Service.cs file in web service website to write the code to get the user details from database
Before writing the WebMethod in Service.cs first add following namespaces
Here we need to remember one point that is adding [WebMethod] before method definition because we need to access web method pulically otherwise it’s not possible to access method publically. If you observe above code I converted dataset to XmlElement t because sometimes we will get error likereturn type dataset invalid type it must be either an IListSource, IEnumerable, or IDataSource to avoid this error I converted dataset to XmlElement.
Here we need to set the database connection in web.config because here I am getting database connection from web.config
Our web service is working fine now we need to know how we can use webservice in our application? Before to know about using web service in application first Deploy your webservice application in your local system if you want to know how to deploy application in your local system check this link deploy application in local system
How to Use Web service in web application?
By using this webservice we can get the user details based on username. For that first create one new web application
Open visual studio ---> Select File ---> New ---> Web Site ---> select ASP.NET Web Site
After creation of new website right click on solution explorer and choose “Add web reference” that would be like this
After select Add Web reference option one window will open like this
Now enter your locally deployed web service link and click Go button after that your web service will found and window will looks like this
Now click on Add Reference button web service will add successfully. Now open your Default.aspx page and design like this