none
Azure storage table Query Entity

    Question

  • Hi Azure experts,

    i was trying to follow the URL: https://msdn.microsoft.com/en-us/library/azure/dd179421.aspx to read the DevStorage Table in my local machine.

    To read table entities using GET method from my machine using POSTMAN google app, i was getting the error.

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
        <code>OutOfRangeInput</code>
        <message xml:lang="en-US">One of the request inputs is out of range.
    RequestId:b11ad4d2-f43c-409c-b0e6-0a5f1339ebab
    Time:2015-11-27T10:58:15.8082158Z</message>
    </error>

    http://127.0.0.1:10002/sampletable(PartitionKey='Account')?$select=PartitionKey,RowKey,empname

    http://127.0.0.1:10002/sampletable()?$select=PartitionKey,RowKey,empname

    Kindly advise how can i querying entities using the approach from below URL for DevStorage table

    https://msdn.microsoft.com/en-us/library/azure/dd179421.aspx

    kindly someone help me on this!

    Thanks


    Thanks, SaravanaBharathi.A

    Friday, November 27, 2015 11:12 AM

All replies

  • Hi,

    Thanks for posting here.

    I suggest you to refer the similar thread.

    https://social.msdn.microsoft.com/Forums/azure/en-us/81dbd510-fb5e-4cfa-80a4-5c1c0db25f36/outofrangeinput-error-when-running-in-azure

    Hope it helps.

    Girish Prajwal

    Friday, November 27, 2015 7:10 PM
    Moderator
  • So this query obviously has problem:

    http://127.0.0.1:10002/sampletable(PartitionKey='Account')?$select=PartitionKey,RowKey,empname

    Please note that "=" sign is not supported. It should be "eq".

    http://127.0.0.1:10002/sampletable(PartitionKey eq 'Account')?$select=PartitionKey,RowKey,empname

    Not sure about the 2nd query. Are you setting all the required headers properly?

    Hope this helps.

    Saturday, November 28, 2015 4:18 PM
  • Hi Gaurav,

    I'm using google POSTMAN app to test the below URL as mentioned by you for GET.

    http://127.0.0.1:10002/sampletable(PartitionKey eq 'Account')?$select=PartitionKey,RowKey,empname

    Headers are,

    Authorization : SharedKeyLite DevStorage:DevStorage

    x-ms-date : Mon, 30 Nov 2015 15:25:14 GMT

    I was received response in Body as below,

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
        <code>OutOfRangeInput</code>
        <message xml:lang="en-US">One of the request inputs is out of range.
    RequestId:ae57744a-7d70-4be9-8ee8-0ace5af661ed
    Time:2015-11-30T09:25:05.1332419Z</message>
    </error>

    I was received Response header as below,

    Content-Length → 343
    Content-Type → application/xml
    Date → Mon, 30 Nov 2015 09:25:05 GMT
    Server → Microsoft-HTTPAPI/2.0
    x-ms-request-id → ae57744a-7d70-4be9-8ee8-0ace5af661ed

    Any help is appreciable.

    similarly i tried using the azure storage account for the same also receiving error!

    Thanks,


    Thanks, SaravanaBharathi.A

    Monday, November 30, 2015 9:31 AM
  • Hi Gaurav / azure experts,

    I have copy pasted the code which is helpful and able to get data with help of partition key and row key combination. But i would like to get the data with any of custom column in a record with json response. Help me to get the code for that please if possible since i have tried by replace the query and end up with error.

                

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

    using System.Net;
    using System.IO;
    using System.Security.Cryptography;
    using System.Globalization;

    namespace webapiclient
    {
        class Program
        {

            public enum SharedKeyAuthorizationScheme
            {
                SharedKey, SharedKeyLite
            };

            static string Account = "yourstoragetablename";
            static string TableEndPoint = "https://yourstorageaccountname.table.core.windows.net/";
            static string storageAccountKey = "yourstorageaccountkey";


            public static String CreateAuthorizationHeader(String canonicalizedString)
            {
                String signature = String.Empty;

                using (HMACSHA256 hmacSha256 = new HMACSHA256(Convert.FromBase64String(storageAccountKey)))
                {
                    Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(canonicalizedString);
                    signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
                }

                String authorizationHeader = String.Format(
                    CultureInfo.InvariantCulture,
                    "{0} {1}:{2}",
                    SharedKeyAuthorizationScheme.SharedKey,
                    Account,
                    signature
                );

                return authorizationHeader;
            }


            public static void GetEntity(String tableName, String partitionKey, String rowKey, String name)
            {
                String requestMethod = "GET";

                String urlPath = String.Format("{0}(PartitionKey='{1}',RowKey='{2}')", tableName, partitionKey, rowKey);

                String storageServiceVersion = "2013-08-15";// "2012-02-12";

                String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
                String canonicalizedResource = String.Format("/{0}/{1}",
                    Account,
                    urlPath);
                String stringToSign = String.Format(
                        "{0}\n\n\n{1}\n{2}",
                        requestMethod,
                        dateInRfc1123Format,
                        canonicalizedResource);
                String authorizationHeader = CreateAuthorizationHeader(stringToSign);

                Uri uri = new Uri(TableEndPoint + urlPath);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
                request.Method = requestMethod;
                request.Headers.Add("x-ms-date", dateInRfc1123Format);
                request.Headers.Add("x-ms-version", storageServiceVersion);
                request.Headers.Add("Authorization", authorizationHeader);
                request.Headers.Add("Accept-Charset", "UTF-8");
                request.Accept = "application/atom+xml,application/xml";


                request.Headers.Add("DataServiceVersion", "2.0;NetFx");
                request.Headers.Add("MaxDataServiceVersion", "2.0;NetFx");

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    Stream dataStream = response.GetResponseStream();
                    using (StreamReader reader = new StreamReader(dataStream))
                    {
                        String responseFromServer = reader.ReadToEnd();
                        Console.WriteLine(responseFromServer);
                        Console.ReadKey();
                    }
                }
            }




            static void Main(string[] args)
            {
                GetEntity("sampletable", "AAA", "0001", "tester2");
            }
        }
    }


    Thanks, SaravanaBharathi.A

    Wednesday, December 09, 2015 8:07 AM
  • Why don't you use Azure Storage Client Library instead of implementing your own?
    Friday, December 25, 2015 1:37 AM