Azure状态服务 - 使用UseUniqueServiceUrl时,Swagger无法使用Kestrel

时间:2017-06-30 07:05:09

标签: c# .net azure swagger

在我的program.cs中使用Kestrel与 ServiceFabricIntegrationOptions.UseUniqueServiceUrl

protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
    var codePackageActivationContext = FabricRuntime.GetActivationContext();
    var environment = new FabricConfigurationLoader(codePackageActivationContext).Get("Conf", "Environment");

    return new[]
    {
        new ServiceReplicaListener(serviceContext =>
            new KestrelCommunicationListener(serviceContext, (url, listener) =>
                new WebHostBuilder()
                    .UseEnvironment(environment)
                    .UseKestrel()
                    .ConfigureServices(
                        services => services
                            .AddSingleton<StatefulServiceContext>(serviceContext)
                            .AddSingleton<IReliableStateManager>(this.StateManager))
                            .UseContentRoot(Directory.GetCurrentDirectory())
                            .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
                            .UseStartup<Startup>()
                            .UseUrls(url)
                            .Build()))
    };
}

这会为我的服务创建唯一的网址,例如:

localhost:53770/f740151b-43eb-455f-8759-e158e4934eb9/131432790864330387/66119e4b-4973-47cf-8471-0bd084a27abe

现在,当我将/swagger/ui添加到此url的末尾时,swagger不起作用:

browser image

我收到以下错误:

the swagger.json file does exist in localhost:53770/f740151b-43eb-455f-8759-e158e4934eb9/131432790864330387/66119e4b-4973-47cf-8471-0bd084a27abe/swagger/v1/swagger.json

,但用户界面无效!

请告知

1 个答案:

答案 0 :(得分:0)

请尝试将SwaggerEndpoint指定为相对。

app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("../swagger/v1/swagger.json", "your service name V1");
            });

另外,需要设置RouteTemplate

app.UseSwagger(c =>
            {
                c.RouteTemplate = "swagger/{documentName}/swagger.json";
            });