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.
Step1: Create a web service using the following steps.
- Go to V.S 2010,2012,13 and take a New Project.
- Select .NET Framework 3.5. and above
- Take a ASP.NET Web Service Application.
- Give it a name and click ok button.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for WebService
/// </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 WebService :System.Web.Services.WebService {
[WebMethod]
public DataSet login(string uname, string pwd)
{ SqlDataAdapter da=new SqlDataAdapter("select * from login where UserName ='"
+ uname +"' and Password ='"+ pwd +"' ",@"Data Source=mithilesh;dataBase=WebService;User Id=sa;Password=12345");
DataSet ds = new DataSet();
da.Fill(ds); return ds;
}
}
Step 4: Now create a web application to consume the service. For doing this, follow the given steps.
- Go to VS and take a New Project.
- Select a ASP.NET Empty Web Application.
- Give it a name and click ok button.
Step 5: Now add service in our web application. Go to Solution Explorer and right-click at our project. Click at Add Web Reference. A new window will open. Its screen-shot is given below.
Step 6: Go to Advanced
Click Ok
Step 7: Go to Add Web Reference
Now paste the URL of our service and click at go button.
Click Add Reference
{ localhost.WebService mk = new localhost.WebService();
lblStatus.Text = "<b style='color:green'>Login Sucessfully</b> " + "<b style='color:green'>and Your Name and Password are</b>:-" + ds.Tables[0].Rows[0][0].ToString() +","+ ds.Tables[0].Rows[0][1].ToString();
else
}
}
-----------------------------X----------------------------------X-------------------------------------
No comments:
Post a Comment