public async Task OpenAsync()

in src/Microsoft.ServiceFabric.AspNetCore/GenericHostCommunicationListener.cs [51:91]


        public async Task<string> OpenAsync(CancellationToken cancellationToken)
        {
            this.host = this.build(this.listener.GetListenerUrl(), this.listener);
            if (this.host == null)
            {
                throw new InvalidOperationException(SR.HostNullExceptionMessage);
            }

            await this.host.StartAsync(cancellationToken);

            var server = this.host.Services.GetService<IServer>();
            if (server == null)
            {
                throw new InvalidOperationException(SR.WebServerNotFound);
            }

            var url = server.Features.Get<IServerAddressesFeature>().Addresses.FirstOrDefault();
            if (url == null)
            {
                throw new InvalidOperationException(SR.ErrorNoUrlFromAspNetCore);
            }

            var publishAddress = this.serviceContext.PublishAddress;

            if (url.Contains("://+:"))
            {
                url = url.Replace("://+:", $"://{publishAddress}:");
            }
            else if (url.Contains("://[::]:"))
            {
                url = url.Replace("://[::]:", $"://{publishAddress}:");
            }

            // When returning url to naming service, add UrlSuffix to it.
            // This UrlSuffix will be used by middleware to:
            //    - drop calls not intended for the service and return 410.
            //    - modify Path and PathBase in Microsoft.AspNetCore.Http.HttpRequest to be sent correctly to the service code.
            url = url.TrimEnd(new[] { '/' }) + this.listener.UrlSuffix;

            return url;
        }