WindowsAzure REST API
Azureテーブルにエンティティを挿入するために使用しようとしています。しかし、私は次のWebExceptionを取得しています:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>AuthenticationFailed</code>
<message xml:lang="en-US">
Server failed to authenticate the request. Make sure the
value of Authorization header is formed correctly including
the signature.
RequestId:bbcf614e-6a12-4fb0-be68-16246853111d
Time:2012-10-03T08:21:46.3010154Z
</message>
</error>
そして、次のコードは認証ヘッダーを作成します:
private String CreateAuthorizationHeader(String canonicalizedString)
{
String signature = string.Empty;
using (HMACSHA256 hmacSha256 = new HMACSHA256(Encoding.UTF8.GetBytes(AzureStorageConstants.Key)))
{
Byte[] dataToHmac = Encoding.UTF8.GetBytes(canonicalizedString);
signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac));
}
String authorizationHeader = String.Format(
CultureInfo.InvariantCulture,
"{0} {1}:{2}",
AzureStorageConstants.SharedKeyAuthorizationScheme,
AzureStorageConstants.Account,
signature);
return authorizationHeader;
}
canonicalizedStringを生成するためのコード
public void InsertEntity(string tablename, string artist, string title)
{
string requestmethod = "POST";
string urlpath = tablename;
string storageserviceversion = "2009-09-19";
string dateinrfc1123format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture);
string contentmd5 = string.Empty;
string contenttype = "application/atom+xml";
String canonicalizedresource = string.Format("/{0}/{1}", AzureStorageConstants.Account, urlpath);
String stringtosign = String.Format(
"{0}\n{1}\n{2}\n{3}\n{4}",
requestmethod,
contentmd5,
contenttype,
dateinrfc1123format,
canonicalizedresource);
String authorizationHeader = CreateAuthorizationHeader(stringtosign);
...
...
}
誰かが私が間違っていることを教えてもらえますか?