Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Saturday, February 26, 2011

WCF Implementation(for retrieve Data and match the data for login)

File---> New WEBSITE---->WCF SERVICES
we have Iservice.cs Interface and second is Service.cs Class

Inside the Iservice.cs (Interface) we have to define one interface for that.(that will be accessible with other application)

[OperationContract]
DataTable GetUserId();

second is....Service.cs Class give the method body which we create interface...

}
public DataTable GetUserId()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kumarConnectionString"].ConnectionString);
string cmd = "select Name from customer";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
da.Fill(ds);

return ds.Tables[0];
}
after that Build the website....

///////Use service with other application.....

create new website

Add services with your application :- Right click on solution explorer there is Add Service Reference select your services otherwise paste the url of service and ok .

////Inside the button click u can acces use that....

protected void Button1_Click(object sender, EventArgs e)
{
ServiceReference1.ServiceClient objService = new ServiceReference1.ServiceClient();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kumarConnectionString"].ConnectionString);
con.Open();
DataTable ds = new DataTable();
ds = objService.GetUserId();
if (ds.Rows.Count > 0)
{
foreach (DataRow item in ds.Rows)
{
string id = item["name"].ToString();
if (id == textUserId.Text)
{
lblMessage.Text = "Valid";
break;
}
else
lblMessage.Text = "InValid";
}

}
}


///////want to use same application.........

Right click on solution explorer on same website and click on AddNewItem pick NewForm ...
Inside new form ..............

Add services with your application :- Right click on solution explorer there is Add Service Reference select your services otherwise paste the url of service and ok .


protected void Button1_Click(object sender, EventArgs e)
{
Service sf = new Service();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["kumarConnectionString"].ConnectionString);
con.Open();
DataTable ds = new DataTable();
ds = sf.GetUserId();
if (ds.Rows.Count > 0)
{
foreach (DataRow item in ds.Rows)
{
string id = item["name"].ToString();
if (id == textUserId.Text)
{
lblMessage.Text = "Valid";
break;
}
else
lblMessage.Text = "InValid";
}

}
}

No comments:

Post a Comment