Click here to Skip to main content
13,355,018 members (57,511 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am building xamarin cross platform portable application.

using following steps:

1.Added service reference. 2.On button click in login page ,I used to validate user from db,if successful then move to next page else show up message.

here is the code.



Problem is if I entered incorrect credentials,than alert does show up, but on other hand if entered correct credentials,then show up

"Unhandle Exception message show up"

I have tried all possible solutions but stuck here for last two days.


What I have tried:

<pre lang="c#"><pre><?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             x:Class="FypXFP.Login">
    <ContentPage.Content>

        <StackLayout>
            <Label Text="UserName" />
            <Entry x:Name="tbuserentry" Placeholder="UserName"></Entry>
            <Label Text="Password"></Label>
            <Entry x:Name="Pwd" IsPassword="True" Placeholder="Password"></Entry>
            <Button x:Name="Save" Clicked="Save_Clicked" Text="Login"></Button>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>



using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace FypXFP
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Login : ContentPage
    {
        private FypXFP.ServiceReference1.CMSServiceClient _client;
        public Login()
        {
            InitializeComponent();
        }

        private void Save_Clicked(object sender, EventArgs e)
        {
            var endpoint = new EndpointAddress("http://192.168.43.101/FYP_Admin/webservices/cmsservice.svc");
            var binding = new BasicHttpBinding
            {
                Name = "basicHttpBinding",
                MaxBufferSize = 2147483647,
                MaxReceivedMessageSize = 2147483647
            };

            TimeSpan timeout = new TimeSpan(0, 0, 30);
            binding.SendTimeout = timeout;
            binding.OpenTimeout = timeout;
            binding.ReceiveTimeout = timeout;

            _client = new FypXFP.ServiceReference1.CMSServiceClient(binding, endpoint);

            string uname = tbuserentry.Text.Trim();
            string password = Pwd.Text.Trim();
            _client.ValidateUserAsync(uname, password);
            _client.ValidateUserCompleted += _client_ValidateUserCompleted;

        }
        public async void Redirect(Boolean Result)
        {
            if (Result == true)
            {
                Navigation.InsertPageBefore(new TicketPage(), this);
                await Navigation.PopAsync();
            }
            else
            {
                await DisplayAlert("Alert", "Something wrong", "Cancel");
            }
        }
        private void _client_ValidateUserCompleted(object sender, ServiceReference1.ValidateUserCompletedEventArgs e)
        {
            if (e.Result == true)
            {
                Device.BeginInvokeOnMainThread(() => {
                    Redirect(true);
                });


            }
            else
            {
                Device.BeginInvokeOnMainThread(() => {
                    Redirect(false);
                });
            }
        }
    }
}
Posted 13-Aug-17 6:02am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 13 Aug 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100