I have a simple Windows Phone 8 application. When App starts, I need to authenticate user, doing a server call. In InitializePhoneApplication(), my WP8 application checks if this data was already obtained in a previous call and stored in IsolatedStorage. If no data is in the IsolatedStorage, a server call is performed. Code:
if ((IsolatedStorageSettings.ApplicationSettings.Contains("loggedin")) &&
(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["loggedin"]).ToLower() == "y"))
{
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
SC = new ServiceClient();
SC.CheckDeviceCompleted += SC_CheckDeviceCompleted;
SC.CheckDeviceAsync(Utility.GetStatus());
}
Here is the code of SC_CheckDeviceCompleted(). This event is raised when the CheckDeviceAsync() returns (on service):
private void SC_CheckDeviceCompleted(object sender, CheckDeviceCompletedEventArgs e)
{
string res = e.Result;
if (!res.Equals(""))
{
IsolatedStorageSettings.ApplicationSettings["loggedin"] = "y";
IsolatedStorageSettings.ApplicationSettings["id"] = res;
RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
RootFrame.Navigate(new Uri("/Authentication.xaml", UriKind.Relative));
}
}
Data received from server are used to select the start page of the application. If an empty string is received, no data is registered on server: so, user must login. Otherwise, user can immediately access the main page of the App.
The problem is that this code does not work. Specifically, server call is not received from service (service does not receive anything), so the SC_CheckDeviceCompleted() method is never executed (because nothing is received from service) and no page is showed.
SC instance is defined as a public static property in App.xaml.cs, App class:
public static ServiceClient SC { get; set; }
My service works perfectly when called from any other page (where I use local ServiceClient variables and not the ServiceClient property defined in App.xaml.cs) of my WP8 application. I can't do service calls from App.xaml.cs file using the ServiceClient property defined in it. Why? What is the problem?