3

I am searching for a way to read settings from a deployed windows azure cloud service with C#. Is there any Azure SDK available to easily load this values?

Screenshot from Azure Portal to show which settings i want to read:

enter image description here

[EDIT1]

I missed to add that I tried to load the settings from an external application and not from the service it self.

Kirill Kobelev
  • 10,252
  • 6
  • 30
  • 51
M. Linn.
  • 33
  • 3

1 Answers1

4

According to your description, I assumed that you could leverage Microsoft Azure Management Libraries to retrieve the configuration settings, you could follow the steps below:

I created a console application and reference the Microsoft Azure Management Libraries, here is the core code:

private static X509Certificate2 GetStoreCertificate(string thumbprint)
{
  List<StoreLocation> locations = new List<StoreLocation>
  { 
    StoreLocation.CurrentUser, 
    StoreLocation.LocalMachine
  };

  foreach (var location in locations)
  {
    X509Store store = new X509Store("My", location);
    try
    {
      store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
      X509Certificate2Collection certificates = store.Certificates.Find(
        X509FindType.FindByThumbprint, thumbprint, false);
      if (certificates.Count == 1)
      {
        return certificates[0];
      }
    }
    finally
    {
      store.Close();
    }
  }
  throw new ArgumentException(string.Format(
    "A Certificate with Thumbprint '{0}' could not be located.",
    thumbprint));
}
static void Main(string[] args)
{
    CertificateCloudCredentials credential = new CertificateCloudCredentials("{subscriptionId}", GetStoreCertificate("{thumbprint}"));
    using (var computeClient = new ComputeManagementClient(credential))
    {
        var result = computeClient.HostedServices.GetDetailed("{your-cloudservice-name}");
        var productionDeployment=result.Deployments.Where(d => d.DeploymentSlot == DeploymentSlot.Production).FirstOrDefault();
    }
    Console.WriteLine("press any key to exit...");
    Console.ReadKey();
}

You could retrieve the configuration settings from productionDeployment.Configuration as follows:

enter image description here

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35