Azure service fabric 在Azure服务结构中使用Http.sys进行端口共享
希望在Azure service fabric中托管2个使用端口80的asp.net core 2网站。在本文中,他们提到了端口共享,但不确定如何配置?有没有提到主机名的方法?使用此类:Azure service fabric 在Azure服务结构中使用Http.sys进行端口共享,azure-service-fabric,Azure Service Fabric,希望在Azure service fabric中托管2个使用端口80的asp.net core 2网站。在本文中,他们提到了端口共享,但不确定如何配置?有没有提到主机名的方法?使用此类: public class HttpSysInstanceListener { public static ServiceInstanceListener[] CreateListener(Type startupType, string endpointName, string rootPath, i
public class HttpSysInstanceListener
{
public static ServiceInstanceListener[] CreateListener(Type startupType, string endpointName, string rootPath, int port)
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, $"{endpointName}", (url, listener) =>
{
return new WebHostBuilder()
.UseHttpSys(options =>
{
options.UrlPrefixes.Add($"http://+:{port}/{rootPath}/");
options.Authentication.Schemes = Microsoft.AspNetCore.Server.HttpSys.AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = null;
})
.ConfigureServices(services => services
.AddSingleton<StatelessServiceContext>(serviceContext)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup(startupType)
.UseUrls(url)
.UseApplicationInsights()
.Build();
}))
};
}
}
公共类HttpSysInstanceListener
{
公共静态服务InstanceListener[]CreateListener(类型startupType、字符串endpointName、字符串rootPath、int-port)
{
返回新服务InstanceListener[]
{
新ServiceInstanceListener(serviceContext=>
新的HttpSysCommunicationListener(serviceContext,$“{endpointName}”,(url,listener)=>
{
返回新的WebHostBuilder()
.UseHttpSys(选项=>
{
options.urlprofixes.Add($“http://+:{port}/{rootPath}/”);
options.Authentication.Schemes=Microsoft.AspNetCore.Server.HttpSys.AuthenticationSchemes.None;
options.Authentication.AllowAnonymous=true;
options.MaxConnections=null;
})
.ConfigureServices(服务=>services
.AddSingleton(serviceContext)
.UseContentRoot(目录.GetCurrentDirectory())
.UseStartup(startupType)
.useURL(url)
.UseApplicationInsights()
.Build();
}))
};
}
}
如果这是一个.NET核心无状态WEB服务API,则使用HttpSys。但是,HttpsSys只能与IIS一起使用,不能与KESTREL一起使用
要在无状态服务中使用HttpSys,请重写CreateServiceInstanceListeners方法并返回HttpSysCommunicationListener实例:
C#
因此,对于端口80上的本地主机,URL应为:
http(s)//localhost.com/WebService/api/foo
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(serviceContext =>
new HttpSysCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
new WebHostBuilder()
.UseHttpSys()
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseStartup<Startup>()
.UseUrls(url)
.Build()))
};
}
.UseUrls(url+="WebService")