Azure テーブル ストレージが 400 Bad Request を返す 質問する

Azure テーブル ストレージが 400 Bad Request を返す 質問する

これをデバッグ モードで実行し、例外の詳細を記載した画像を添付しました。何が間違っていたのかをどうすればわかりますか? テーブルにデータを挿入しようとしていました。Azure で詳細を確認できませんか?

注意: ストレージは私のマシンではなく Windows Azure にあります。テーブルは作成されましたが、データを挿入するときにこのエラーが発生します。

ここに画像の説明を入力してください

// Retrieve the storage account from the connection string.
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***");

// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

// Create the table if it doesn't exist.
CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");
table.CreateIfNotExists();

挿入コードは次のとおりです。

public static void SetStatus(Employee e, bool value)
{
    try
    {
        // Retrieve the storage account from the connection string.
        Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###");

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" table.
        CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");

        // Create a new customer entity.

        if (value == true)
        {
            EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id);
            empHistory.IsOnline = true;
            empHistory.OnlineTimestamp = DateTime.Now;
            TableOperation insertOperation = TableOperation.Insert(empHistory);
            table.Execute(insertOperation);
        }
        else
        {
            TableQuery<EmployeeOnlineHistory> query = new TableQuery<EmployeeOnlineHistory>()
                .Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, e.Id.ToString()));
            EmployeeOnlineHistory entity = table.ExecuteQuery(query).Take(1).FirstOrDefault();

            if ((entity!=null)&&(entity.IsOnline))
            {
                entity.IsOnline = false;
                entity.OfflineTimestamp = DateTime.Now;
                entity.OnlineTime = (entity.OfflineTimestamp - entity.OnlineTimestamp);
                TableOperation updateOperation = TableOperation.Replace(entity);
                table.Execute(updateOperation);
            }
            else
            {
                EmployeeOnlineHistory empHistory = new EmployeeOnlineHistory(e.Id);
                empHistory.IsOnline = false;
                empHistory.OfflineTimestamp = DateTime.Now;
                TableOperation insertOperation = TableOperation.Insert(empHistory);
                table.Execute(insertOperation);
            }
        }
    }
    catch (Exception ex)
    {
        //var details = new System.IO.StreamReader(((Microsoft.WindowsAzure.Storage.StorageException)ex)..Response.GetResponseStream()).ReadToEnd();
        LogFile.Error("EmployeeOnlineHistory.setStatus",ex);
    }
}

ベストアンサー1

400 エラーは、プロパティの値に問題があることを意味します。これを確認する 1 つの方法は、Fiddler を介して要求/応答をトレースし、Windows Azure ストレージに送信されている実際のデータを確認することです。

推測ですが、あなたのコードをざっと見たところ、モデルには日付/時刻型のプロパティ(OfflineTimestamp、OnlineTimestamp)がいくつかあり、特定のシナリオではそのうちの1つがデフォルト値で初期化されていることがわかりました。日付時刻.最小値「ご注意ください」日付/時刻型属性に許可される最小値は 1601 年 1 月 1 日 (UTC) です。Windows Azureで[http://msdn.microsoft.com/en-us/library/windowsazure/dd179338.aspx]そうでないかどうか確認してください。そうである場合は、デフォルト値が設定されないように、null 値許容型のフィールドにすることができます。

以下の Juha Palomäki の回答もご覧ください...彼が提案する例外には、もう少し役立つメッセージが含まれている場合があります (RequestInformation.ExtendedErrorInformation.ErrorMessage)

おすすめ記事