Last active
December 16, 2015 10:29
-
-
Save valeryjacobs/5420699 to your computer and use it in GitHub Desktop.
Tool to setup a working environment on Windows Azure with minimal effort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var publishSettingsFile = | |
@"C:\temp\........credentials.publishsettings"; | |
XDocument xdoc = XDocument.Load(publishSettingsFile); | |
var managementCertbase64string = | |
xdoc.Descendants("PublishProfile").Single().Attribute("ManagementCertificate").Value; | |
var importedCert = new X509Certificate2( | |
Convert.FromBase64String(managementCertbase64string)); | |
string thumbprint = importedCert.Thumbprint; | |
string subscriptionId = xdoc.Descendants("Subscription").First().Attribute("Id").Value; | |
X509Store store = new X509Store(StoreName.My); | |
store.Open(OpenFlags.ReadWrite); | |
store.Add(importedCert); | |
store.Close(); | |
X509Store store = new X509Store(StoreName.My); | |
store.Open(OpenFlags.ReadWrite); | |
X509Certificate2 managementCert = | |
store.Certificates.Find(X509FindType.FindByThumbprint, thumbrprint, false)[0]; | |
var req = (HttpWebRequest)WebRequest.Create( | |
string.Format("https://management.core.windows.net/{0}/services/hostedservices", | |
subscriptionId)); | |
req.Headers["x-ms-version"] = "2011-10-01"; | |
req.ClientCertificates.Add(managementCert); | |
XNamespace xmlns = "http://schemas.microsoft.com/windowsazure"; | |
Console.WriteLine(string.Join("n", | |
XDocument.Load(req.GetResponse().GetResponseStream()) | |
.Descendants(xmlns + "ServiceName").Select(n => n.Value).ToArray())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment