gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:21:41 25 4
gpt4 key购买 nike

我正在尝试创建一个 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;
}
}

最佳答案

这是因为您在 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;
}

关于c# - FabricConnectionDeniedException - 在哪里设置 Azure Service Fabric 连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com