【发布时间】:2017-03-29 04:23:59
【问题描述】:
我有一个 Service Fabric Stateless Asp.Net Core 服务。
该服务使用 HTTP 端点。 我需要支持 HTTPS 端点以及 HTTP
到目前为止我的步骤:
- 已将证书添加到 Azure KeyVault
-
将 ApplicationManifest.xml 更新为:
<Policies> <EndpointBindingPolicy EndpointRef="ServiceEndpointHttps" CertificateRef="Certificate" /> </Policies>
最后
<Certificates>
<EndpointCertificate X509StoreName="MY" X509FindValue="XXXX" Name="Certificate" />
</Certificates>
- 在 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 不起作用。
另外,启用它后,我如何(从门户或 powershell)将 KeyVault 中的证书安装到已部署和运行的虚拟机规模集?
【问题讨论】: