【问题标题】:FabricConnectionDeniedException - Where do I setup Azure Service Fabric connections?FabricConnectionDeniedException - 在哪里设置 Azure Service Fabric 连接?
【发布时间】:2016-07-20 15:09:51
【问题描述】:

我正在尝试创建一个 Visual Studio 项目模板,其中包含一个带有 StatelessService 的 Azure Service Fabric 项目。

在样板代码Program EntryPoint 代码中,我得到一个FabricConnectionDeniedException我在哪里设置连接信息或以其他方式修复此异常?我正在针对本地集群管理器运行。我查看了各种.xml 配置文件,但什么也没看到。我需要在集群管理器中将我的应用列入白名单吗?

这是我从 Azure Service Fabric 复制的样板代码:

    private static void Main()
    {
        try
        {
            // Creating a FabricRuntime connects this host process to the Service Fabric runtime.
            using (var fabricRuntime = System.Fabric.FabricRuntime.Create())
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // RegisterServiceType maps a service type name to a .NET class.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.
                fabricRuntime.RegisterServiceType(
                    "RunSetManagerServiceType", 
                    typeof(RunSetManagerService));

                ServiceEventSource.Current.ServiceTypeRegistered(
                    Process.GetCurrentProcess().Id, 
                    typeof(RunSetManagerService).Name);

                // Prevents this host process from terminating to keep the service host process running.
                Thread.Sleep(Timeout.Infinite);  
            }
        }
        catch (Exception e)
        { 
           // !!!!!! GETTING FabricConnectionDeniedException HERE !!!!!
            ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
            throw;
        }
    }

【问题讨论】:

    标签: c# azure azure-service-fabric


    【解决方案1】:

    这是因为您在 Service Fabric 运行时环境之外运行服务 EXE。当你将你的服务编译成一个 EXE 时,你不能只执行它自己;您必须将其“部署”到 Service Fabric 集群,Service Fabric 运行时环境将为您执行该集群。

    如果您通过 Visual Studio 进行部署,请确保您的 应用程序 项目设置为启动项目,而不是服务项目(启动项目将显示为 粗体在解决方案资源管理器中)。

    另外,与您看到的错误无关,只是提醒一下:当您升级到最新的 2.0.135 SDK 时,您需要更新您的服务注册码才能使用新的 ServiceRuntime:

    try
    {
        ServiceRuntime.RegisterServiceAsync("RunSetManagerServiceType",
            context => new RunSetManagerService(context)).GetAwaiter().GetResult();
    
        ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Stateless1).Name);
    
        // Prevents this host process from terminating so services keep running.
        Thread.Sleep(Timeout.Infinite);
    }
    catch (Exception e)
    {
        ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
        throw;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-31
      • 2016-12-08
      • 1970-01-01
      • 2016-12-06
      • 2018-11-06
      • 2019-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多