azureazure-compute-emulator

Is there a way to programmatically determine the actual IP used for an endpoint in the Azure DevFabric?


I'm hosting an IIS application under the Azure development fabric.

When an application is deployed to the Azure compute emulator, a temporary IIS application is created that listens on a port around 5100. Incoming requests from the public endpoint are redirected to this port.

It seems, though, that the Azure development fabric does not always use the public port that has been declared in the project configuration. So, for instance, our application should expose a public port 80 -- but when I run this it's almost always port 81, but sometimes port 82, and so on.

So I can ensure that URLs created in my application are correct, I'd like to know what this external port is.

Unfortunately I can't simply look at Request.Url.Port, as this is the port number of the temporary application -- typically 5100. RoleEnvironment.CurrentRoleInstance.InstanceEndpoints, doesn't work either as that also returns the ports as seen from the server, 5100 and following.


Solution

  • Figured this out by using Reflector to look into csrun.exe.

    It seems that the SDK DLL Microsoft.ServiceHost.Tools.DevelopmentFabric is the key to this, in particular the methods FabricClient.GetServiceDeployments() and FabricClient.GetServiceInformation(). So:

    using System; using Microsoft.ServiceHosting.Tools.DevelopmentFabric;

    class Program
    {
        static void Main(string[] args)
        {
            FabricClient client = FabricClient.CreateFabricClient();
    
            foreach (string tenantName in client.GetServiceDeployments())
            {
                var information = client.GetServiceInformation(tenantName);
                foreach (var item in information)
                {
                    Console.WriteLine(string.Format("{0} {1} {2} {3}", item.ContractName, item.InterfaceName, item.UrlSpecification, item.Vip));
                }
            }
    
            Console.ReadLine();
        }
    }
    

    What I'm after is returned as the item.Vip.

    Note, obviously, that this will only work in the development fabric ... but that's what I was looking for here, anyway.