c# – FabricConnectionDeniedException – 在哪里设置Azure Service Fabric连接?

前端之家收集整理的这篇文章主要介绍了c# – FabricConnectionDeniedException – 在哪里设置Azure Service Fabric连接?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个Visual Studio项目模板,其中包含一个带有StatelessService的Azure Service Fabric项目.

在锅炉板Program EntryPoint代码中,我收到了FabricConnectionDeniedException.我在哪里设置连接信息或以其他方式修复此例外?我正在运行本地群集管理器.我查看了各种.xml配置文件,但没有看到任何内容.我是否需要在Cluster Manager中将我的应用程序列入白名单?

这是我从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;
        }
    }

解决方法

这是因为您在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;
}
原文链接:https://www.f2er.com/csharp/91299.html

猜你在找的C#相关文章