locked
Not connecting to the internet

    Question

  • Good day

    I finished developing an app with an activation interface but is not connecting to the internet even when the internet is on and the the activation PIN is inputed

    Check the code below

    <!--TitlePanel contains the name of the application and page title-->
            <StackPanel Grid.Row="0" Margin="12,17,0,28">
                <TextBlock Text="Redemption Hymnal" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0" FontSize="30" Foreground="Black"/>
                <TextBlock Text="Activation" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontSize="50" Foreground="Black"/>
            </StackPanel>
            <PasswordBox x:Name="pin" HorizontalAlignment="Left" Margin="12,268,0,0" VerticalAlignment="Top" Width="458" SelectionForeground="#FF0A3057" BorderBrush="#FF0A3057"/>
            <TextBlock HorizontalAlignment="Left" Margin="23,236,0,0" TextWrapping="Wrap" Text="Enter Pin*" VerticalAlignment="Top" Foreground="#FF0A3057" Width="117" FontSize="24"/>
            <Button x:Name="activate" Content="Activate" HorizontalAlignment="Left" Margin="321,365,0,0" VerticalAlignment="Top" Background="#FF0A3057" BorderThickness="0" Height="70" Width="136" Click="activate_Click"/>
            <ProgressBar x:Name="pgb" HorizontalAlignment="Left" Height="18" Margin="0,184,0,0" VerticalAlignment="Top" Width="480" Background="#FF0A3057" IsIndeterminate="True" Foreground="#FF0A3057" Visibility="Collapsed"/>
            <HyperlinkButton x:Name="get" Content="Get Activation Pin" HorizontalAlignment="Left" Margin="23,365,0,0" VerticalAlignment="Top" Foreground="#FF0A3057" Click="get_Click"/>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using Microsoft.Phone.Controls;
    using Microsoft.Phone.Shell;
    using System.Diagnostics;
    using Microsoft.Phone.Tasks;
    
    namespace RedemptionHymnal
    {
        public partial class Activation : PhoneApplicationPage
        {
            public Activation()
            {
                InitializeComponent();
            }
    
            private void activate_Click(object sender, RoutedEventArgs e)
            {
                if (pin.Password == null || pin.Password == "")
                {
                    MessageBox.Show("Please enter valid Pin");
                }
                else
                {
                    Activate();
                }
            }
    
            public void Activate()
            {
                try
                {
    
               
                WebClient client = new WebClient();
                client.DownloadStringAsync(new Uri("http://iopenheavens.com/hymnalconnect/payservice.php?code=" + pin.Password.ToString() + "&device=" + App.GetID()));
                client.DownloadStringCompleted += client_DownloadStringCompleted;
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to connect to Internet or server is not responding.");
    
                    Debug.WriteLine("Error: " + ex.ToString());
                }
            }
    
            void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                try
                {
                    if(e.Result.ToString() == "failed")
                    {
                        MessageBox.Show("Wrong Activation Pin Inserted");
                    }
                    else
                    {
                        App.SaveSetting("activation", "true");
                        MessageBox.Show("Activation Successful");
                        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to connect to Internet or server is not responding.");
                    Debug.WriteLine("Error: " + ex.ToString());
                    
                }
                //throw new NotImplementedException();
            }
    
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                if (NavigationService.BackStack.Count() == 1)
                {
                    NavigationService.RemoveBackEntry();
                }
                
                base.OnNavigatedTo(e);
            }
    
            private void get_Click(object sender, RoutedEventArgs e)
            {
                WebBrowserTask web = new WebBrowserTask();
                web.Uri = new Uri("http://redemptionhymnal.com/buypin.html", UriKind.RelativeOrAbsolute);
                web.Show();
            }
            
    
            
        }
    }

    I will like evangelist in the house to look at the snippet, let me know what am doing wrong

    Regards


    Jayjay john

    Thursday, September 25, 2014 1:58 PM

Answers

  • Hi

    Ignore the debugging question i have solved it.

    The question now is how can i make the app save the PIN, for the app not to ask for PIN when next the user is using the app.

    Look at the above code and tell me how to implement it

    Regards


    Jayjay john

    Saturday, October 4, 2014 8:24 PM
  • Hi John,

    Since you have solved the issue, I will close it. If you have new qeustion, please post a new thread.

    For your new question, Microsoft provides an easy way to save your password. You can use PasswordVault class. Your info are saved into a credential locker of credentials. Code looks like the following.

    Get the credential locker.

     var passwordVault = new Windows.Security.Credentials.PasswordVault();

    Write pin code.

    passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("http://www.microsoft.com", "username", "pin code"));

    Read pin code.

    var data = passwordVault.Retrieve("http://www.microsoft.com", "username");

    Please note, this class is used in windows phone 8.1 project, including Silverlight and runtime project.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 8, 2014 7:27 AM
    Moderator

All replies

  • First, I'd validate or encode the password. 

    If I entered a pin/password of "0&dev=1" your request URI will not work as expected on the server.

    Next, reverse these two:

     client.DownloadStringAsync(new Uri("http://iopenheavens.com/hymnalconnect/payservice.php?code=" + pin.Password.ToString() + "&device=" + App.GetID()));
                client.DownloadStringCompleted += client_DownloadStringCompleted;

    To

    Make them:

                client.DownloadStringCompleted += client_DownloadStringCompleted;
     client.DownloadStringAsync(new Uri("http://iopenheavens.com/hymnalconnect/payservice.php?code=" + pin.Password.ToString() + "&device=" + App.GetID()));
    

    What could be happening is that your Download string completes, but you don't get notified. 


    Darin R.

    Thursday, September 25, 2014 2:14 PM
  • Thank you for the response,

    I will try it and get back to you

    Regards


    Jayjay john

    Thursday, September 25, 2014 5:23 PM
  • Good day

    When i tried it again it still showing below response instead of activation successful

    Unable to connect to Internet or server is not responding

    Kindly help out or should i send the whole project (solution) to you as an attachment

    Regards


    Jayjay john

    Friday, September 26, 2014 11:53 AM
  • Hi

    Can anyone help me with above question and code

    Thanks in advance


    Jayjay john

    Thursday, October 2, 2014 10:14 AM
  • What is the exception that you are getting?

    Darin R.

    Thursday, October 2, 2014 1:54 PM
  • I am not getting any exception what am saying is that when i input the activation code it shows
    Unable to connect to Internet or server is not responding
    with availability of internet connection, kindly look at the lines of code and tell me where am getting it wrong

    Jayjay john

    Thursday, October 2, 2014 2:50 PM
  • Your code is catching an exception to display that message.  What is the Debug output that is written on the next line when that happens?

    Darin R.

    Thursday, October 2, 2014 2:56 PM
  • Hi

    Thank you for your response this is what am getting when debugging

    "A first chance exception of type 'System.UnauthorizedAccessException' occurred in Microsoft.Phone.ni.dll"

    Kindly proffer a solution

    Regards


    Jayjay john

    Saturday, October 4, 2014 7:01 PM
  • Hi

    Ignore the debugging question i have solved it.

    The question now is how can i make the app save the PIN, for the app not to ask for PIN when next the user is using the app.

    Look at the above code and tell me how to implement it

    Regards


    Jayjay john

    Saturday, October 4, 2014 8:24 PM
  • Hi John,

    Since you have solved the issue, I will close it. If you have new qeustion, please post a new thread.

    For your new question, Microsoft provides an easy way to save your password. You can use PasswordVault class. Your info are saved into a credential locker of credentials. Code looks like the following.

    Get the credential locker.

     var passwordVault = new Windows.Security.Credentials.PasswordVault();

    Write pin code.

    passwordVault.Add(new Windows.Security.Credentials.PasswordCredential("http://www.microsoft.com", "username", "pin code"));

    Read pin code.

    var data = passwordVault.Retrieve("http://www.microsoft.com", "username");

    Please note, this class is used in windows phone 8.1 project, including Silverlight and runtime project.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, October 8, 2014 7:27 AM
    Moderator