Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to change the url dynamically of a web service?

$
0
0

I am doing an application at work that need to change dinamically the url of a web service, the application consist in a Log-In page, after the user log in for first time then I changes the value of the static string, the next code does not works, the new url does not replace the old url and the same WCF service is called. I make with right click and add service reference

public static class Constantes
    {
        public static string applicationId = "3ada26f8-e6ea-450f-86e2-4a348b712898";
        public static string endPoint = "http://advancedsecurityservice.iydsapp.com/UserService.svc";
 }

public class UserServiceAgent
 {
    public static IUserService _userService;

    static UserServiceAgent()
    {
        _userService = new UserServiceClient(new BasicHttpBinding(), new EndpointAddress(Constantes.endPoint));
    }

    public static ValidateUserResponse ValidateUser(string applicationId, string account, string password, int errorId = 0, string errorDescription = "", bool isValidUser = false)
    {
        ValidateUserResponse ValidateUserResponse = null;

        var ValidateUserRequest = new ValidateUserRequest
        {
            ApplicationId = applicationId,
            Account = account,
            Password = password,
            ErrorId = errorId,
            ErrorDescription = errorDescription,
            IsValidUser = isValidUser
        };

        try
        {
            ValidateUserResponse = Task.Factory.FromAsync(_userService.BeginValidateUser,
                                                          _userService.EndValidateUser,
                                                          ValidateUserRequest,
                                                          TaskCreationOptions.None).Result;
        }
        catch (Exception) { }

        return ValidateUserResponse;
    }
}

protected void ButtonAcceptClicked(object sender, EventArgs e)
    {
        var UserServiceAgent = new UserServiceAgent();

        string user = EntryUser.Text.Trim();
        string password = EntryPassword.Text.Trim();

        var response = UserServiceAgent.ValidateUser(Constantes.applicationId, user, password);

        if (response.ErrorId == 0 && response.IsValidUser)
        {
            if (Application.Current.Properties.ContainsKey("UserId"))
            {
                if (Application.Current.Properties["UserId"].ToString() == response.ValidateUserResult.UserId)
                {
                    DisplayAlert("Mensaje", "Ya estas logeado", "Aceptar");
                }
                else
                {
                    Application.Current.Properties["SystemClientId"] = response.ValidateUserResult.SystemClientId;
                    Application.Current.Properties["SessionId"] = response.ValidateUserResult.SessionId;
                    Application.Current.Properties["UserId"] = response.ValidateUserResult.UserId;

                    DisplayAlert("Usuario", Application.Current.Properties["UserId"].ToString(), "Aceptar");
                }
            }
            else
            {
                Constantes.endPoint = "http://securitytest.iydsapp.com/UserService.svc";

                Application.Current.Properties.Add("SystemClientId", response.ValidateUserResult.SystemClientId);
                Application.Current.Properties.Add("SessionId", response.ValidateUserResult.SessionId);
                Application.Current.Properties.Add("UserId", response.ValidateUserResult.UserId);

                DisplayAlert("Usuario", Application.Current.Properties["UserId"].ToString(), "Aceptar");
            }
        }
        else
            DisplayAlert("Error", "Datos invalidos", "Aceptar");
    }

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>