0
votes

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?

1

1 Answers

0
votes

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.