1

Azure publishsettings ファイルがあります。次に、サブスクリプション内で指定された名前のストレージ アカウントにアクセスする必要があります。

C#でそれを行うには?

4

1 に答える 1

3

以下にいくつかのコードを書き、動作することを確認しました。これは Wade の投稿に基づいています: Programmatically Installing and Using Your Management Certificate with the New .publishsettings File . 次に、 Get Storage Account Keysメソッドを呼び出します。Wade の投稿で言及されているように、いくつかのヒントがあります。証明書を作成してローカルにインストールし、それを使用して SM API を呼び出して、.publishsettings ファイルを削除できるようにすることをお勧めします。SM API 証明書情報が含まれているため、削除するか、安全に保管してください。このコードは、簡潔にするためにインストール ビットを実行しませんが、Wade の投稿にはそれがあります。

        var publishSettingsFile =
        @"C:\yourPublishSettingsFilePathGoesHere";

        XDocument xdoc = XDocument.Load(publishSettingsFile);

        var managementCertbase64string =
            xdoc.Descendants("PublishProfile").Single().Attribute("ManagementCertificate").Value;

        var managementCert = new X509Certificate2(
            Convert.FromBase64String(managementCertbase64string));

        // If you have more than one subscription, you'll need to change this
        string subscriptionId = xdoc.Descendants("Subscription").First().Attribute("Id").Value;
        string desiredStorageService = "yourStorageServiceName";

        var req = (HttpWebRequest)WebRequest.Create(
            string.Format("https://management.core.windows.net/{0}/services/storageservices/{1}/keys",
                                            subscriptionId,
                                            desiredStorageService));
        req.Headers["x-ms-version"] = "2012-08-01";
        req.ClientCertificates.Add(managementCert);

        XNamespace xmlns = "http://schemas.microsoft.com/windowsazure";

        XDocument response = XDocument.Load(req.GetResponse().GetResponseStream());

        Console.WriteLine("Primary key: " + response.Descendants(xmlns + "Primary").First().Value);
        Console.WriteLine("Secondary key: " + response.Descendants(xmlns + "Secondary").First().Value);

        Console.Read();
于 2013-03-18T18:12:50.780 に答える