how to check user is valid or not based on login details using WCF service method Task<T> async ?

Good Morning

I am now able to access WCF service method from PCL using Task. But i am confused that how can i get the actual result which my WCF service method return form database query etc.

Like first i have login screen where user can enter their username / password and click on "Login". If login successful then i need to show user other screen. If login failed then to show same screen with some message.

So that on Login button click event i am calling WCF Service method, which will check in my SQL Server database and return result. So based on WCF service method return result i need to check whether to show other screen or stay user on same screen etc.

Below is some code snippet so far i have written

Method which called WCF method using Task

public async Task GetEngineerLogin(string LoginId, string Password, string uniqueId)
{
try
{
var asyncResult = await Task.Factory.FromAsync<string, string, string, string>(todoService.BeginGetEngineerLogin, todoService.EndGetEngineerLogin, LoginId, Password, uniqueId, null, TaskCreationOptions.None);

            return asyncResult;
        }
        catch (Exception ex)
        {
            return "Error:" + ex.Message;
        }
    }

Login Button click event code

void onLoginClicked(object sender, EventArgs e)
{

        try
        {


            Task<string> strResult = App.TodoManager.GetEngineerLogin(txtUserName.Text, txtPassword.Text, "a3bb7a45820c0857");


    //If i tried like below then it's gooing to Hang no result coming from WCF ?
            //string strResult = App.TodoManager.GetEngineerLogin(txtUserName.Text, txtPassword.Text, "a3bb7a45820c0857").Result;

    // Here based on strResult ,, i need to check whether user is valid or not
    // how to do that ?

        }
        catch (Exception ex)
        {
            throw;
        }


    }

So how to achieve this ? Please Really need some help / insights on it as i am totally new in Xamarin mobile development.

Can anyone please help me here ?

thanks,

rohan

Sign In or Register to comment.