WCF - Bool returns Void

Asked

Viewed 17 times

0

Hello, good morning, good morning! When I call the WCF service on the client side, a function that was made to return bool is returning void.. and even asks for more parameters than those indicated within the WCF that would be the Email and Password, since it serves to verify the login.

WCF works perfectly, I’m not really able to unite the customer to the service..

The code below is WCF:

public bool Login(string email, string password)
{
    bool ativo = false;
    try
    {
        if (string.IsNullOrEmpty(email) == false && string.IsNullOrEmpty(password) == false)
        {
            var comando = new SqlCommand();
            comando.Connection = Connection.conexao_DB;
            Connection.Conetar_DB();

            SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM login where email = @Email and password = @Password", Connection.conexao_DB);
            cmd.SelectCommand.Parameters.Add(new SqlParameter("@Email", email));
            cmd.SelectCommand.Parameters.Add(new SqlParameter("@Password", password));
            DataTable dt = new DataTable();
            cmd.Fill(dt);

            List<LoginModel> getUser = new List<LoginModel>();
            foreach (DataRow row in dt.Rows)
            {
                LoginModel user = new LoginModel();
                user.Email = row["email"].ToString();
                user.Password = row["password"].ToString();
                if (email == row["email"].ToString() && password == row["password"].ToString())
                {
                    ativo = true;
                };
                getUser.Add(user);
            }
            Connection.Desconetar_DB();
            //return ativo;
        }
    }
    catch (Exception)
    {
        throw new FaultException("ERROR");
    }
    return ativo;
}

Inside the Iservice.Cs:

namespace WcfMarketPlace
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        bool Login(string email, string password);
    }
}
Do lado do cliente:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TESTE.wcfMarketPlace;
namespace TESTE
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public void loginT_Click(object sender, EventArgs e)
        {
            try
            {
                wcfMarketPlace.Service wcf = new wcfMarketPlace.Service();
                bool ativo = false;

                ativo = wcf.Login(loginEmail.Text, loginPassword.Text);
            }
            catch 
            {
                Response.Write("<script>alert('Usuario Incorreto')</script>");
            }
            //wcf.Close();
        }
    }
}

It may be a basic mistake, but I really don’t understand since I’m a beginner, I appreciate any kind of help! :)

Thank you!

  • Friend, it is impossible for a bool method not to return anything (void). Debug the code and you will see that you are invoking another method with the same name, which is void, and expect other arguments.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.