私は学生で、ユーザーがAzureでホストされているサービスのインスタンス数を変更できるようにするアプリケーションを作成しようとしています。これは、サービス (http://msdn.microsoft.com/en-us/library/windowsazure/ee460809.aspx)の新しい構成ファイルをアップロードすることです。私の問題は、以下のコードでレスポンスを取得しようとすると「リモートサーバーがエラーを返しました:(403)Forbidden」というエラーが表示されることです。私はエラーが証明書とは何かである必要がありますが、 GETリクエストは正常に実行され、ここで使用するのと同じ証明書を使用して正しい応答が得られます。どんな助けも非常に高く評価されています.configは新しい設定ファイルです。Azureサービス管理のAPI設定を変更する
公共ボイドchangeConfiguration(文字列serviceNameは、文字列deploymentSlot、文字列の設定、文字列deploymentName)
{
byte[] encodedConfigbyte = new byte[config.Length];
encodedConfigbyte = System.Text.Encoding.UTF8.GetBytes(config);
string encodedConfig = Convert.ToBase64String(encodedConfigbyte);
Uri changeConfigRequestUri = new Uri("https://management.core.windows.net/" + subscriptionId + "/services/hostedservices/" + serviceName + "/deployments/" + deploymentName + "/?comp=config)");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(changeConfigRequestUri);
request.Headers.Add("x-ms-version", "2010-10-28");
request.Method = "POST";
string bodyText = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<ChangeConfiguration xmlns=\"http://schemas.microsoft.com/windowsazure" + ">" + "<Configuration>" + encodedConfig + "</Configuration>" + "<TreatWarningsAsError>false</TreatWarningsAsError>" + "<Mode>Auto</Mode>"+"</ChangeConfiguration>";
byte[] buf = Encoding.UTF8.GetBytes(bodyText);
request.ContentType = "text/xml";
request.ContentLength = buf.Length;
StreamWriter writer = new StreamWriter(request.GetRequestStream());
var data = Encoding.ASCII.GetBytes(buf.ToString());
writer.Write(data);
writer.Flush();
writer.Close();
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
try
{
certStore.Open(OpenFlags.ReadOnly);
}
catch (Exception e)
{
if (e is CryptographicException)
{
Console.WriteLine("Error: The store is unreadable.");
}
else if (e is SecurityException)
{
Console.WriteLine("Error: You don't have the required permission.");
}
else if (e is ArgumentException)
{
Console.WriteLine("Error: Invalid values in the store.");
}
else
{
throw;
}
}
X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
certStore.Close();
if (certCollection.Count == 0)
{
throw new Exception("Error: No certificate found containing thumbprint " + thumbprint);
}
X509Certificate2 certificate = certCollection[0];
request.ClientCertificates.Add(certificate);
//Error occurs in line below
WebResponse response = (HttpWebResponse)request.GetResponse();
try
{
response = request.GetResponse();
}
catch (WebException e)
{
string test = e.Message;
}