[英]How can I connect my silverlight application with SQL server 2005
I am trying to connect my silverlight application with Sql server 2005 for login purpose. 我正在尝试将我的silverlight应用程序与Sql server 2005连接以进行登录。 I am totally new to silverlight and want to build my own website in Silverlight.
我对Silverlight很新,想在Silverlight中建立自己的网站。 Please suggest useful sites for referance.
请建议有用的网站以供参考。 Thanx in advance.
Thanx提前。
You have to use a Web Service example WCF. 您必须使用Web服务示例WCF。 1) Add a WCF to your project.
1) 向项目添加WCF。
//This is your interface Class.
namespace SilverlightApplication1.Web
{
[ServiceContract]
public interface IService1
{
[OperationContract]
bool UserLogin(string email, string password);
}
}
//This is your service code behind class
namespace SilverlightApplication1.Web
{
public class Service1 : IService1
{
public bool UserLogin(string email,string password)
{
// Your logic here to verify user name and password
}
}
}
//After creating the service. Add a reference to your application.**
2) Add the Service Reference to your Silverlight application. 2) 将服务引用添加到Silverlight应用程序。 Right click on your project, Select the web references option and add the service to your project.
右键单击项目,选择Web引用选项并将服务添加到项目中。 Now if you have a button control on your form which will submit the data to your wcf service.
现在,如果您的表单上有一个按钮控件,它将把数据提交给您的wcf服务。 Add the following code in its click event.
在其click事件中添加以下代码。
Service1Client proxy ;
private void button1_Click(object sender, RoutedEventArgs e)
{
proxy.UserLogin += new EventHandler<InsertDataCompletedEventArgs>(proxy_UserLogin);
proxy.UserLogin(txtEmail.Text, "Password");
}
void proxy_UserLogin(object sender, InsertDataCompletedEventArgs e)
{
if (e.Result == true)
{
lblMesg.Content = "User Login successfully";
}
else
{
lblMesg.Content = "User record not found";
}
}
In the button Click event call that service. 在按钮Click事件中调用该服务。
If you want a SQL Server connection for logging on, you can create a Silverlight Business Application project. 如果要使用SQL Server连接进行登录,可以创建Silverlight业务应用程序项目。 It has user logon built in. This way, you can concentrate on the rest of your Silverlight application's features.
它内置了用户登录。这样,您可以专注于Silverlight应用程序的其余功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.