Service Fabric Asp.Net Core无状态服务上的HTTP和HTTPS终结点

弗朗切斯科·克里斯塔洛(Francesco Cristallo)

我有一个Service Fabric无状态Asp.Net Core服务。

该服务与HTTP端点一起使用。我需要与HTTP一起支持HTTPS端点

到目前为止,我的步骤:

  1. 将证书添加到Azure KeyVault
  2. 使用以下命令更新了ApplicationManifest.xml:

    <Policies>
      <EndpointBindingPolicy EndpointRef="ServiceEndpointHttps" CertificateRef="Certificate" />
    </Policies>
    

最后

<Certificates>
    <EndpointCertificate X509StoreName="MY" X509FindValue="XXXX" Name="Certificate" />
  </Certificates>
  1. 在ServiceManifest.xml中使用端口443添加了端点

现在,我要启用HTTPS终结点。在Program.cs中,我有以下内容:

  public static void Main(string[] args)
        {
            ServiceRuntime.RegisterServiceAsync("MyType", context => new WebHostingService(context, "ServiceEndpoint")).GetAwaiter().GetResult();

            Thread.Sleep(Timeout.Infinite);
        }
 internal sealed class WebHostingService : StatelessService, ICommunicationListener
        {
            private readonly string _endpointName;

            private IWebHost _webHost;

            public WebHostingService(StatelessServiceContext serviceContext, string endpointName)
                : base(serviceContext)
            {
                _endpointName = endpointName;
            }

            #region StatelessService

            protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
            {
                return new[] { new ServiceInstanceListener(_ => this) };
            }

            #endregion StatelessService

            #region ICommunicationListener

            void ICommunicationListener.Abort()
            {
                _webHost?.Dispose();
            }

            Task ICommunicationListener.CloseAsync(CancellationToken cancellationToken)
            {
                _webHost?.Dispose();

                return Task.FromResult(true);
            }

            Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken)
            {
                var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName);

                string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}";

                _webHost = new WebHostBuilder().UseKestrel()
                                               .UseContentRoot(Directory.GetCurrentDirectory())
                                               .UseStartup<Startup>()
                                               .UseUrls(serverUrl)
                                               .Build();

                _webHost.Start();

                return Task.FromResult(serverUrl);
            }

            #endregion ICommunicationListener
        }

如何在这里注册HTTPS端点?

添加第二个ServiceRuntime.RegisterServiceAsync不起作用。

另外,启用它后,如何从KeyVault将证书从KeyVault安装到已经部署并正在运行的Virtual Machines Scale集中?

弗朗切斯科·克里斯塔洛(Francesco Cristallo)

我使用Azure应用程序网关解决了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Service Fabric 本地群集 ASP.NET Core https 终结点

在Azure Service Fabric中,无状态Web API和ASP.NET Core Web API之间有什么区别?

Service Fabric(ASP.NET Core)中的Appsettings

如何在Azure Service Fabric ASP.NET Core有状态服务中获取PartitionInfo?

Azure Service Fabric:直接在ASP.NET Core有状态服务中使用可靠的集合

Service Fabric上的SignalR ASP.NET Core因HTTP 410 GONE而失败

从.Net Core无状态服务中调用.Net框架Service Fabric Actor

具有Asp.net核心依赖注入的Service Fabric状态服务

创建Service Fabric Api服务仅允许ASP .NET Core 2.1

Service Fabric本地群集上的托管环境Asp.net Core

使用默认ASP.NET Core DI容器在Service Fabric上设置依赖项注入

.NET Core的Service Fabric可靠服务

用于 asp.net 核心的 Service Fabric 中 docker 中的 HTTPS 不起作用

在Azure Service Fabric中的ASP.NET Core中使用WebListener

Azure Service Fabric中ASP.NET Core应用程序中的WebpackDevMiddleware

Service Fabric Asp.net Core Kestrel HttpClient 以最小负载挂起

Service Fabric .Net Framework 4.5.1和4.6

通过https在Azure Service Fabric上的无状态Web Api

如何将Service Fabric服务上下文注入asp.net核心中间件?

将Windows身份验证与带有ASP.NET Core的Azure Service Fabric一起使用

如何使用共享群集上相同端口的子路径在Azure Service Fabric上部署Asp.Net Core应用

带有nginx和.NET核心服务的Service Fabric

具有 2 个公开的 https 终结点和不同端口的 Service Fabric 群集

Service Fabric,Akka.net和Persistent actor集成

带有远程侦听器的 Azure Service Fabric ASP .net

Service Fabric 和 IConfigurationBuilder

如何对无状态Service Fabric服务进行分区

MassTransit和Service Fabric状态服务?

在Service Fabric中的.NET Core上运行的Angular应用程序中出现错误