我有一个Service Fabric无状态Asp.Net Core服务。
该服务与HTTP端点一起使用。我需要与HTTP一起支持HTTPS端点
到目前为止,我的步骤:
使用以下命令更新了ApplicationManifest.xml:
<Policies>
<EndpointBindingPolicy EndpointRef="ServiceEndpointHttps" CertificateRef="Certificate" />
</Policies>
最后
<Certificates>
<EndpointCertificate X509StoreName="MY" X509FindValue="XXXX" Name="Certificate" />
</Certificates>
现在,我要启用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集中?
我使用Azure应用程序网关解决了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句