Introduction:

Here I am creating a web service for a login check and consuming it in a web application. Follow the given steps to do it.

Step1:
Create a web service using the following steps.

Step 2: Write the following code on the .asmx.cs page.

using System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Services;
using
System.Data.SqlClient;
using
System.Data;

namespace
loginwebservice
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public DataSet login(string uname, string pwd)
{
SqlDataAdapter da = new SqlDataAdapter("select * from login where user_name ='" + uname + "' and password='" + pwd + "' ",
@"DataSource=SERVER_NAME;Initial Catalog=EMP;Integrated Security=True");
DataSet
ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}

Step 3: Run this application.

Output:

login check through web service

Step 4: Now create a web application to consume the service. For doing this, follow the given steps.

Step 5: Now add service in your web application. Go to Solution Explorer and right click at your project. Click at Add Web Reference. A new window will open. Its screen-shot is given below.

login check through web service

Step 6: Run the web application.

Output:

login check through web service

Write the user name and password in TextBoxes and click the ok Button. In this example, Database name is EMP which has a table Login. There is only one record in Login table - abc is user_name and xyz is password. Do right input for user name and password and click the ok button.

Output:

login check through web service

Now do wrong input for user name and password and click the ok button.

Output:

login check through web service