Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 101.5k

How to navigate in xamarin cross platform application

Aug 13 2017 11:10 AM
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.
<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);              
   });       
      }       
  }     } }




Answers (4)