0

我已經在Azure上設置了服務結構集羣,並且運行了2個服務的應用程序。現在我希望能夠連接到瀏覽器中的服務,就像我在本地主機上運行它時一樣。 該應用程序使用Owin和Swagger。以下是它在本地主機上的運行方式:running on localhost。當我嘗試從Azure連接到它時,出現超時錯誤。我在應用程序中使用了端口20002和20001,並且在設置羣集時(端口19000,19080,20001和20002在我的羣集中打開),我打開了端口。這是我在資源管理器中的服務:Service in the explorer。羣集設置爲證書安全性,並且我已將證書添加到瀏覽器(我正在使用它連接到資源管理器)。我對CreateServiceInstanceListeners代碼:連接到服務結構應用程序端點

 protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
    { 
     return Context.CodePackageActivationContext.GetEndpoints() 
      .Where(endpoint => endpoint.Protocol.Equals(EndpointProtocol.Http) || endpoint.Protocol.Equals(EndpointProtocol.Https)) 
      .Select(endpoint => new ServiceInstanceListener(serviceContext => new OwinCommunicationListener("", new Startup(), serviceContext))); 
    } 

和我的代碼爲OpenAsync:

 public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, StatelessServiceContext serviceInitializationParameters) 
    { 
     _startup = startup; 
     _appRoot = appRoot; 
     _parameters = serviceInitializationParameters; 
    } 


    public Task<string> OpenAsync(CancellationToken cancellationToken) 
    { 
     var serviceEndpoint = 
      _parameters 
      .CodePackageActivationContext 
      .GetEndpoint("ServiceEndpoint"); 

     var port = serviceEndpoint.Port; 
     var root = 
      String.IsNullOrWhiteSpace(_appRoot) 
      ? String.Empty 
      : _appRoot.TrimEnd('/') + '/'; 


     //TODO: Make localhost configable 
     _listeningAddress = String.Format(
      CultureInfo.InvariantCulture, 
      "http://+:{0}/{1}", 
      port, 
      root 
     ); 
     _serverHandle = WebApp.Start(
      _listeningAddress, 
      appBuilder => _startup.Configuration(appBuilder) 
     ); 

     var publishAddress = _listeningAddress.Replace(
      "+", 
      FabricRuntime.GetNodeContext().IPAddressOrFQDN 
     ); 

     ServiceEventSource.Current.Message("Listening on {0}", publishAddress); 
     return Task.FromResult(publishAddress); 
    } 

和我serviceEndpoint:一個

<Endpoints> 
    <Endpoint Name="ServiceEndpoint" Port="20002" /> 
</Endpoints> 

來總結我的問題:我如何才能存取權限我的服務織物的應用服務在我的瀏覽器中,使用大舉和所有?

+0

轉發(任意)外部端口的內部端口20002在您的負載平衡器上 – Mardoxx

回答

1

最好的方法是讓您在端口19081上使用反向代理。您必須在集羣創建狀態下啓用它。

然後您必須爲反向代理設置負載平衡器規則。 在Azure上負載均衡服務織物的基本設置不具有TCP端口19081的規則,但是你可以複製的19000

規則之後,例如:

  • 你的應用程序名稱爲SampleApp
  • 您的服務名稱是SampleService 託管在端口20002
  • 您通常在 http://localhost:20002/api/values
  • 公共IP˚F局部達到您服務或羣集是51.140.xx.xx

那麼現在,你可以達到你的服務 http://51.140.xx.xx:19081/SampleApp/SampleService/api/values(假設你不保護你的反向代理終點)

相關問題