[英]How do I inject IHttpClientFactory in my Azure Service Fabric application?
[英]FabricConnectionDeniedException - Where do I setup Azure Service Fabric connections?
我正在嘗試創建一個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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.