azure - How to get full list of CloudConfiguration from inside a web service at runtime? -


configurationmanager has appsettings name-value collection cloudconfigurationmanager has getsetting(string) method can config settings 1 1 if know key.

is there way whole config of role runtime?

the root cause want make strong typed configuration in order abstract away , make code more testable. using cloudconfigurationmanager directly implicit dependency want remove abstraction want stub in tests. find practical. brings me question.

i not want use library fx.configuration.azure because have carry dependency altogether because requires inheritance of base class.

afaik, there's no direct method available give information.

however there's workaround can use. involves making use of service management api's get deployment operation. operation return xml , 1 of element there configuration contains service configuration file in base64 encoded format. can read element, convert string , parse xml configurationsettings elements. it's child elements contains settings.

for this, either write own wrapper on service management rest api or make use of azure management library.

update

so here's sample code listing configuration settings service configuration file using azure management library. it's simple console app hacked in short amount of time has lot of scope of improvement :). management certificate, have used data publish setting file.

you have install azure management library nuget package in console application:

install-package microsoft.windowsazure.management.libraries

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using microsoft.windowsazure; using microsoft.windowsazure.management.compute; using system.security.cryptography.x509certificates; using system.xml.linq;  namespace readconfigurationsettingsusingazuremanagementlibrary {     class program     {         static string subscriptionid = "<subscription-id>";         static string managementcertcontents = "<base64 encoded management certificate string publish setting file>";//certificate string azure publish settings file         static string cloudservicename = "<your cloud service name>";         static string ns = "http://schemas.microsoft.com/servicehosting/2008/10/serviceconfiguration";         static void main(string[] args)         {             var managementcetificate = new x509certificate2(convert.frombase64string(managementcertcontents));             var credentials = new certificatecloudcredentials(subscriptionid, managementcetificate);              var computemanagementclient = new computemanagementclient(credentials);             var response = computemanagementclient.hostedservices.getdetailed(cloudservicename);             var deployment = response.deployments.firstordefault(d => d.deploymentslot == microsoft.windowsazure.management.compute.models.deploymentslot.production);             if (deployment != null)             {                 var config = deployment.configuration;                 xelement configxml = xelement.parse(config);                 var roles = configxml.descendants(xname.get("role", ns));                 foreach (var role in roles)                 {                     console.writeline(role.attribute("name").value);                     console.writeline("-----------------------------");                     var configurationsettings = role.element(xname.get("configurationsettings", ns));                     foreach (var element in configurationsettings.elements(xname.get("setting", ns)))                     {                         var settingname = element.attribute("name").value;                         var settingvalue = element.attribute("value").value;                         console.writeline(string.format("{0} = {1}", settingname, settingvalue));                     }                     console.writeline("==========================================");                 }             }             console.readline();         }     } } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -