Windows Azure Compute Emulator(SDK 1.8)在使用VS2012但不使用VS2010的干净计算机上具有多个角色实例的奇怪行为

Windows Azure Compute Emulator(SDK 1.8)在使用VS2012但不使用VS2010的干净计算机上具有多个角色实例的奇怪行为,azure,azure-compute-emulator,Azure,Azure Compute Emulator,您是否曾经尝试过在windows azure emulator中运行托管服务,其中包含完整的IIS和多个角色实例?几天前,我注意到一个web角色的多个实例中,一次只有一个是IIS中的startet。下面的屏幕截图说明了该行为,屏幕截图前面的消息框显示了该行为的原因。尝试在IIS管理器中启动一个已停止的网站时,会出现消息框 示例云应用程序包含两个web角色:MvcWebRole1和WCFServiceWebRole1,每个角色配置为使用三个实例。我的第一个想法是:“当然!在真实的azure世界中

您是否曾经尝试过在windows azure emulator中运行托管服务,其中包含完整的IIS和多个角色实例?几天前,我注意到一个web角色的多个实例中,一次只有一个是IIS中的startet。下面的屏幕截图说明了该行为,屏幕截图前面的消息框显示了该行为的原因。尝试在IIS管理器中启动一个已停止的网站时,会出现消息框

示例云应用程序包含两个web角色:MvcWebRole1和WCFServiceWebRole1,每个角色配置为使用三个实例。我的第一个想法是:“当然!在真实的azure世界中不会发生端口冲突,因为每个角色实例都是自己的虚拟机。它无法在模拟器中工作!”但经过一些研究和分析azure compute emulator的许多部分后,我发现compute emulator为每个角色实例创建了唯一的IP(在我的示例中,从127.255.0.0到127.255.0.5)(http://blogs.msdn.com/b/avkashchauhan/archive/2011/09/16/whats-new-in-windows-azure-sdk-1-5-each-instance-in-any-role-gets-its-own-ip-address-to-match-compute-emulator-close-the-cloud-environment.aspx)微软员工的Avkash Chauhan也描述了这种行为。得出结论后,我提出了以下问题:为什么compute emulator(更准确地说是DevFC.exe)不将相应角色的IP添加到每个网站的绑定信息中?

我手动将IP添加到每个网站上,Tadaaaaaa:每个网站都可以在没有任何冲突的情况下启动。下一个屏幕截图显示了更改后的绑定信息

再一次:为什么模拟器不为我做这件事?我写了一个小的静态助手方法,在每个角色开始时为我做绑定扩展。也许有人想使用它:

public static class Emulator
{
    public static void RepairBinding(string siteNameFromServiceModel, string endpointName)
    {
        // Use a mutex to mutually exclude the manipulation of the iis configuration.
        // Otherwise server.CommitChanges() will throw an exeption!
        using (var mutex = new System.Threading.Mutex(false, "AzureTools.Emulator.RepairBinding"))
        {
            mutex.WaitOne();

            using (var server = new Microsoft.Web.Administration.ServerManager())
            {
                var siteName = string.Format("{0}_{1}", Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id, siteNameFromServiceModel);
                var site = server.Sites[siteName];

                // Add the IP of the role to the binding information of the website
                foreach (Binding binding in site.Bindings)
                {
                    //"*:82:"
                    if (binding.BindingInformation[0] == '*')
                    {
                        var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endpointName];
                        string bindingInformation = instanceEndpoint.IPEndpoint.Address.ToString() + binding.BindingInformation.Substring(1);
                        binding.BindingInformation = bindingInformation;
                        server.CommitChanges();
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
            }

            // Start all websites of the role if all bindings of all websites of the role are prepared.
            using (var server = new Microsoft.Web.Administration.ServerManager())
            {
                var sitesOfRole = server.Sites.Where(site => site.Name.Contains(RoleEnvironment.CurrentRoleInstance.Role.Name));
                if (sitesOfRole.All(site => site.Bindings.All(binding => binding.BindingInformation[0] != '*')))
                {
                    foreach (Site site in sitesOfRole)
                    {
                        if (site.State == ObjectState.Stopped)
                        {
                            site.Start();
                        }
                    }
                }
            }

            mutex.ReleaseMutex();
        }
    }
}
我调用helper方法如下

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        if (RoleEnvironment.IsEmulated)
        {
            AzureTools.Emulator.RepairBinding("Web", "ServiceEndpoint");
        }

        return base.OnStart();
    }
}
我明白了


我在三台不同的机器上有这种行为,它们都是格式化的,并且最近安装了全新的windows 8、Visual Studio 2012和Azure SDK 1.8以及Azure工具。因此,重新安装Azure SDK和工具(正如Anton所建议的那样)不应该改变任何事情。但我的三台机器的清洁度是关键!安东,你的机器上是否安装了Visual Studio 2010,并且至少安装了VS2010 SP 1?我使用ILSpy分析了
IISConfigurator.exe
,找到了将网站绑定信息中的IP设置为
'*'
(而不是
127.255.0.*
)。它取决于静态属性Microsoft.WindowsAzure.Common.Workarounds.BindToAllIpsWorkaroundEnabled。此方法在内部使用Microsoft.WindowsAzure.Common.Workarounds.TryGetVS2010SPVersion,如果Visual Studio 2010的SP级别小于1,则会将IP绑定设置为
“*”
请重试GetVS2010SPVersion
检查四个注册表项,我不知道为什么其中一个注册表项存在于我的注册表中,并返回Visual Studio 2010 SP级别0(我从未在这三台计算机中的任何一台上安装过VS2010!!!)。当我将
HKEY\U LOCAL\U MACHINE\SOFTWARE\Wow6432Node\Microsoft\DevDiv\vs\SERVICEING\10.0\SP
的值从0更改为10时(应该使用大于0的值)Azure Emulator开始将角色的
127.255.0.*
IP设置为IIS中所有网站上的绑定信息,并且所有网站都已正确启动。

这似乎是一个非常奇怪的行为。我一直在本地运行多个实例,没有任何问题。您是否可以尝试修复Azure Tools/SDK installati打开。最好的选择是从程序/功能中完全卸载名称中包含“Azure”的所有内容。然后重新启动计算机,然后从中干净地安装最新的Azure SDK/工具