2014-09-24 26 views
0
  • 登錄我有一個WCF和我的類就可以了。(作爲一個例子登錄類)如何重定向其他頁面後成功的一類在WCF

    • ,我有其他應用程序使用C#,我希望用戶可以通過這個 應用程序登錄使用WCF登錄類,並且用戶在成功登錄後重定向到其他頁面 。感謝幫助我。
    • 和我如何定義異常消息?在課堂或應用程序?在WCF服務

登錄類:

public class Service1 : IService1 
    { 
     public bool UserLogin(Login userL) 
     { 
      SqlConnection con = new SqlConnection(); 
      con.ConnectionString = ConfigurationManager.ConnectionStrings["BCSConnectionString"].ConnectionString; 
      con.Open(); 
      bool result = false; 
      string Message; 
      using (SqlCommand cmd = new SqlCommand("SELECT Username,Password FROM Users where [email protected] and [email protected]", con)) 
      { 
       cmd.Parameters.AddWithValue("@Username", userL.Username); 
       cmd.Parameters.AddWithValue("@Password", userL.Password); 
       SqlDataReader reader = cmd.ExecuteReader(); 
       if (reader.HasRows) 
       { 
        result = true; 
       } 
       else 
       { 
        result = false; 
       } 
       con.Close(); 
      } 
      return result; 
     } 

代碼隱藏其他App

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     ServiceReference1.Service1Client objServiceClientobjService = new ServiceReference1.Service1Client(); 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      Login UserLogin = new Login(); 
      textBox1.Text = UserLogin.Username; 
      textBox1.Text = UserLogin.Password; 

     } 
    } 
} 

回答

0

試試這個代碼在你的button1_Click();

Login UserLogin = new Login(); 
    UserLogin.Username = textBox1.Text; 
    UserLogin.Password = textBox2.Text; 
    if(objServiceClientobjService.UserLogin(UserLogin)) 
     { 
       Response.Redirect("Home.html"); // your page to go after valid user login 
     } 
    else 
     { 
      // show error code 
     } 
+0

謝謝,但沒有工作:( – aziz 2014-09-24 10:29:31

+0

有你創建的數據和服務合同是否正確?什麼是錯誤? – 2014-09-25 04:49:37

+0

參數化查詢「(@username爲nvarchar(4000),@密碼爲nvarchar(4000))選擇Userna '期望沒有提供的參數'@Username' – aziz 2014-09-25 05:25:51

相關問題