0

I have a server application (a .NET console application that listens on a TCP port) that I need to run in an Azure VM instead of a Worker or Web Role, and I need that app to be able to determine its own public/internet endpoint IP and port (for example that was created/assigned when the VM was created through the Management Portal). The internal TCP port that the app listens to is the same on all VMs, but the external/internet port will obviously be unique per VM instance (I am not using the Azure load balancer).

I tried modifying my .NET console application to try and determine the host Virtual Machine's publically-facing IP address and ports by using RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[i].IPEndpoint, but RoleEnvironment.CurrentRoleInstance throws an exception ("role discovery data is unavailable") and RoleEnvironment.IsAvailable is always false. The documentation says that this should be possible:

The RoleEnvironment class can be used on standalone components in an Azure VM outside of an Azure role. These components can be programs that can be run by, for example, remoting into the role instance and starting the component from the command line. These processes must be run with elevated privileges to access the RoleEnvironment class.

I am running my console application by Remote Desktoping to the VM and right-clicking my .exe and selecting Run as Administrator, but yet RoleEnvironment.IsAvailable is still false. Do I need to somehow install the Windows Azure Integration Components onto the VM? All of the links online talk about doing it in Hyper-V when preparing a Hyper-V VM to be hosted in Azure; but in this case I'm creating the VM directly in Azure from the start by using the Management Portal and selecting the default Windows Server 2012 R2 Datacenter image. I don't know how to install them in this case, or if it's even still supported (most of the links that talk about the Windows Azure Integration Components are from 2011).

So the ultimate question is: How can a standalone application running in an Azure VM determine the public endpoints for that VM?

Kael Rowan
  • 98
  • 5

1 Answers1

0

See the PowerShell command used in this answer: https://stackoverflow.com/a/18194296/2899711 - if you review which API calls it is making you may be able to craft the right call. The PowerShell Cmdlets are open sourced so you can see what API calls they are using for the Cmdlet.

Community
  • 1
  • 1
Simon W
  • 5,481
  • 3
  • 24
  • 35
  • That PowerShell command you linked to requires that the VM name is already known by the caller. In my case it's a newly spawned VM (from a sysprepped image) that doesn't know its own information. – Kael Rowan Feb 17 '14 at 02:15
  • I'm a little confused re-reading your question... you want to determine the public IP / endpoint on the box but you've RDP'd into it so you must know the IP / address. I'd change the approach and use a management host to push the configuration to the new VM when it's spawned using something like PowerShell Remoting. – Simon W Feb 18 '14 at 09:54
  • I'm RDP'ing into the box while I'm initially setting it the master image, but after that point I'm sysprep'ing it and using that as a base image to spawn many more. I don't want to have to RDP into each spawned copy and manually enter its endpoint deails. I'd be happy to create a PowerShell script that I can run that 1) spawns a new VM from the base/master image, 2) creates the VM's endpoint with an unused public port, 3) invokes a command on the newly-spawned VM to set the endpoint details into the VM's environment or writes to a .txt file on the VM's disk or whatever. Is that possible? – Kael Rowan Feb 19 '14 at 15:57