How to read Windows Azure Application Endpont IP Address and Port values in the Startup Task

 In the following example I have a startup task Startup.cmd which launch another batch file showconfvalues.cmd which will show the IP address and Port Value.

 

Startup.cmd:

cd /d "%~dp0"

Start /w showconfvalues.cmd

 

showconfvalues.cmd:

@echo on

@echo Your IP Address is: %ADDRESS%

@echo Your PORT is: %PORT%

 

In the Service Definition below you can see I am using the Port value as 8999:

 

ServiceDefinition.csdef:

 

 <?xml version="1.0" encoding="utf-8"?>
 <ServiceDefinition name="AzureCmdApp" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
 <WorkerRole name="CmdWorkerRole" vmsize="ExtraSmall">
 <Runtime>
 <Environment>
 <Variable name="ADDRESS">
 <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@address" />
 </Variable>
 <Variable name="PORT">
 <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/Endpoints/Endpoint[@name='HttpIn']/@port" />
 </Variable>
 </Environment>
 <EntryPoint>
 <ProgramEntryPoint commandLine="Startup.cmd" setReadyOnProcessStart="true" />
 </EntryPoint>
 </Runtime>
 <Endpoints>
 <InputEndpoint name="HttpIn" protocol="tcp" port="8999" />
 </Endpoints>
 </WorkerRole>
 </ServiceDefinition>
 

ServiceConfiguration.cscfg:

 

 <?xml version="1.0"?>
 <ServiceConfiguration xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="https://www.w3.org/2001/XMLSchema" serviceName="AzureCmdApp" xmlns="https://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
 <Role name="CmdWorkerRole">
 <ConfigurationSettings />
 <Instances count="1" />
 </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 IP address and Port as below:

IP Address: 127.255.0.0

Port: 8999

 

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

 

Get this project from github as below: