服务织物样品如单词计数的Web应用程序监听端口在这样的子路径部署在Azure服务织物Asp.Net核心应用:如何使用子路径在集群上共享相同的端口
http://localhost:8081/wordcount
这种配置的代码是:(见GitHub上https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/Services/WordCount/WordCount.WebService/WordCountWebService.cs文件)
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(initParams => new OwinCommunicationListener("wordcount", new Startup(), initParams))
};
}
有了这个配置,我们可以使用相同的端口在同一个集群上部署的其他Web应用程序(8081)
http://localhost:8081/wordcount
等。
但Asp.Net Core项目模板是不同的,我不知道如何添加侦听器配置的子路径。
下面的代码是我们所拥有的项目模板(Program.cs中类WebHostingService):
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener(_ => this) };
}
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);
}
语义是有点不同,但都在同一个点结束。 的问题是,即使我想补充的子路径在的serverUrl结束但这并没有工作和web应用程序总是响应根http://localhost:8081/
见我如何下面的代码片段尝试:
string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}/app1";
如何使用asp.net核心实现与“经典”网络应用程序相同的结果?
我们的目标是在Azure上发布的80端口,让用户像一个更好的体验:
谢谢你很多!
https://docs.microsoft。com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-aspnetcore#服务结构集成中间件 – LaPuyaLoca
伟大的加法@LaPuyaLoca –