Azure Compute Emulator: Is it possible to control the IP of individual instances?

前端 未结 2 1997
轻奢々
轻奢々 2021-01-12 16:36

Working with the June 2012 Azure SDK, Visual Studio 2010, and IIS Express, I have a web application which has been running on 127.255.0.2. I\'m using ACS for authentication,

2条回答
  •  不要未来只要你来
    2021-01-12 16:52

    I don't know if my experience match exactly the descripted scenario but I think it can, at least, be an inspiration.

    In my solution I have four distinct cloud services, every one have a web role, and every one must know the url of other services to works properly. When in production I know exactly the urls of all my services and I can refer to each service by its domain name. But when it's time do debug this can be a nightmare because there is no option to bind a cloud service to a specific IP address (and port) and DevFabric can't guarantee that a particular cloud service maintain the same address between two different debug session.

    I have solved the problem with a simple technique:

    In my WebRoles I refer always to domain name like debug.myservice.com or debug.myotherservice.com.

    The local ip address is resolved using the hosts file you can find in:

    windows/system32/drivers/etc/hosts
    

    by append some simple statements like, for example:

    127.0.0.1 debug.myservice.com
    127.0.0.2 debug.myotherservice.com
    

    This solve the problem but can be extremely boring because you need to update manually the hosts file every time you launch a new debug session.

    But there is a simple and powerful solution. You know you can setup a simple startup script that is executed every time the cloud service is initialized, you can find details here:

    http://msdn.microsoft.com/en-us/library/windowsazure/hh180155.aspx

    Also you can run different script when you are running on the cloud or in the emulator.

    What I do is to run a script that automatically update the hosts file every time my cloud service are initialized in the emulator (and only in the emulator) environment.

    Here the script:

    IF "%ComputeEmulatorRunning%" == "true" (
        cd Startup
        UpdateDnsHostsOnDebugEnv.exe MyCompany.MyService.Site.WebRole debug.myservice.com
        cd..
    )
    

    and here what you need to add to ServiceDefinition.csdef in order to run the script in the startup:

    
        
           
               
                   
                
           
         
    
    

    Notice the use of the UpdateDnsHostsOnDebugEnv.exe program. This is a simple console app that I wrote that simply run csrun.exe and parse the result to extract the local endpoint address of the role and update the hosts file.

    Hope this help.

提交回复
热议问题