This project is read-only.


Dec 30, 2011 at 9:32 PM


Can we use the DataServiceContext.CreateQuery<T> to query Azure storage table directly from the phone? I am aware of the security issue w/ the key, but setting that aside, I am just wondering whether it's even possible.  If possible, any tip on where to put the azure storage security key in the header of the request will be helpful.




Jan 15, 2012 at 12:42 PM

Hi Tony,

Did you find the answer to your question ? You can certainly store your credentials on the phone even though it represents a security risk. You don't have to manually add the required headers, just use the TableServiceContext class and pass a StorageCredentialsAccountAndKey instance into the constructor. The StorageCredentials class will do the work of setting the appropriate headers for you.


Jan 17, 2012 at 3:29 PM

Hi Yacine,


There's no CreateQuery<T> funciton in the TableServiceContext class. It's only in the DataServiceContext class.



Jan 17, 2012 at 11:32 PM


The Windows Phone version of DataServiceContext doesn't expose CreateQuery<T> either, you should build the Uri manually and pass it to the BeginExecute method along with a callback to send the query to the service and retrieve the response.



Jan 21, 2012 at 4:38 PM

Hi Yacine,

I haven't seen any example on how BeginExecute can query Azure Table directly from the Windows Phone (without having to go thru a web instance). Do you have an example somewhere I can look at?



Jan 22, 2012 at 12:45 AM

Sure, here's an example that uses DataServiceCollection.LoadAsync() instead - under the covers LoadAsync calls BeginExecute. Make sure you change the value of AzureStorageTableProxyEndpoint in app.xaml to the uri your storage account in the cloud or local.

        public MainPage()

            storageAccount = App.Current.Resources["StorageAccount"].ToString();
            storageKey = App.Current.Resources["StorageKey"].ToString();
            var credentials = new StorageCredentialsAccountAndKey(storageAccount, storageKey);

            tableContext = new TableServiceContext(

            ContactsList = new DataServiceCollection<Contact>(tableContext);

            DataContext = ContactsList;


        private void LoadContacts()
            var tableUri = new Uri(tableContext.BaseUri.ToString()
                + "/" + tableName, UriKind.Absolute);

            ContactsList.LoadCompleted += (s, e) =>
                if (e.Error != null)
                    throw new Exception(e.Error.Message);
                if (ContactsList.Continuation != null)



Jan 22, 2012 at 3:26 AM

These days I find that I use our NuGet packages quite a bit more - if you decide to use the Phone.Storage NuGet you'll see a slight variation. Here's some code from an app I'm writing:

    DataServiceCollection<CloudNote> cloudNotesCollection;

    private void QueryCloudNotes()
        var context = CloudStorageContext.Current.Resolver.CreateTableServiceContext();

        cloudNotesCollection = new DataServiceCollection<CloudNote>(context);
        cloudNotesCollection.LoadCompleted += this.OnTableLoaded;
        var tableUri = new Uri(


    protected virtual void OnTableLoaded(object sender, LoadCompletedEventArgs e)
        List<CloudNote> cloudNotes = cloudNotesCollection.ToList();

        listNotes.ItemsSource = cloudNotes;

What's nice about the NuGets is we now have a StorageInitializer which lets you do development directly against the storage service but later you can flip it so that you proxy through services running in Windows Azure (thereby not risking your keys). You should check it out.

Jan 24, 2012 at 2:34 AM

Thank you Wade. The nugets works like a charm on both emulator and actual storage. Two thumbs up!!

Thank you also to Yacine for the tip.

Jan 24, 2012 at 3:56 AM

Glad it helped!

Thank you too for your help, Yacine!