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(假设你不保护你的反向代理终点)

相关问题