0

我正在尝试将我的 silverlight 应用程序与 Sql server 2005 连接以进行登录。我对 Silverlight 完全陌生,想在 Silverlight 中建立自己的网站。请推荐有用的网站以供参考。提前谢谢。

4

3 回答 3

1

您必须使用 Web 服务示例 WCF。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)将服务引用添加到您的 Silverlight 应用程序。 右键单击您的项目,选择 Web 引用选项并将服务添加到您的项目中。现在,如果您的表单上有一个按钮控件,它将向您的 wcf 服务提交数据。在其单击事件中添加以下代码。

 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";
        }
    }

在按钮 Click 事件中调用该服务。

于 2012-07-16T05:59:01.983 回答
1

这可能会对您有所帮助 http://www.codeproject.com/Articles/37522/7-Simple-Steps-to-Connect-SQL-Server-using-WCF-fro

于 2012-07-16T05:59:31.097 回答
0

If you want a SQL Server connection for logging on, you can create a Silverlight Business Application project. It has user logon built in. This way, you can concentrate on the rest of your Silverlight application's features.

于 2012-07-16T08:41:18.727 回答