Avkash Chauhan's Blog

Windows Azure, Windows 8, Cloud Computing, Big Data and Hadoop: All together at one place.. One problem, One solution at One time...

How to access Service Configuration settings in Windows Azure Startup Task

How to access Service Configuration settings in Windows Azure Startup Task

Rate This
  • Comments 2

In this example I will show you how you can access Service Configuration settings in Windows Azure Startup Task. The startup task is Startup.cmd which is launching another batch file name showconfvalues.cmd.

 

The Startup.cmd is as below:

cd /d "%~dp0"

Start /w showconfvalues.cmd

 

The showconfvalues.cmd is as below:

@echo on

@echo Your STRING 1 is: %CONFSTRING1%

@echo Your STRING 2 is: %CONFSTRING2%

 

The Windows Azure Application Service Definition file is as below:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCmdApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="CmdWorkerRole" vmsize="ExtraSmall">
<Runtime>
<Environment>
<Variable name="CONFSTRING1">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='SettingXYZ']/@value" />
</Variable>
<Variable name="CONFSTRING2">
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/ConfigurationSettings/ConfigurationSetting[@name='SettingABC']/@value" />
</Variable>
</Environment>
<EntryPoint>
<ProgramEntryPoint commandLine="Startup.cmd" setReadyOnProcessStart="true" />
</EntryPoint>
</Runtime>
<Endpoints>
<InputEndpoint name="HttpIn" protocol="tcp" port="8999" />
</Endpoints>
<ConfigurationSettings>
<Setting name="SettingXYZ" />
<Setting name="SettingABC" />
</ConfigurationSettings>
</WorkerRole>
</ServiceDefinition>

The Windows Azure Application Service Configuration file is as below:

<?xml version="1.0"?>
<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serviceName="AzureCmdApp" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="CmdWorkerRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="SettingXYZ" value="This is Setting 1 XYZ" />
<Setting name="SettingABC" value="This is Setting 2 ABC" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>

You can launch this application from Windows Azure SDK Command prompt in the Administrator mode as below:

 

When running this application you will see the results showing your configuration values as below:

 Your STRING 1 is: This is Setting 1 XYZ

Your STRING 2 is: This is Setting 2 ABC

 

 Project Files:

  • build.cmd
  • pack.cmd
  • run.cmd
  • ServiceConfiguration.cscfg
  • ServiceDefinition.csdef
  • CmdWorkerRole <FOLDER>
    • Startup.cmd 
    • showconfvalues.cmd

 

Study more about xPath Values in Windows Azure

 

Download this this project from github as below:

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post
  • Does this only work in Azure SDK 1.5?

  • The support for XPATH element is started from Azure SDK 1.5 and newer so you can not use it with older SDK.

Page 1 of 1 (2 items)