azure - 连接到 Service Fabric 应用程序终结点

标签 azure azure-service-fabric endpoint service-fabric-stateless

我已在 Azure 上设置了一个 Service Fabric 群集,并且有一个正在运行 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>

总结我的问题:如何使用 swagger 等在浏览器中访问我的 Service Fabric 应用程序服务?

最佳答案

最好的方法是在端口 19081 上使用反向代理。您必须在集群创建状态下启用它。

然后,您必须为反向代理设置负载均衡器规则。 Azure 负载均衡器上服务结构的基本设置没有 TCP 端口 19081 的规则,但您可以复制 19000 的规则。

之后例如:

  • 您的应用程序名称是 SampleApp
  • 您的服务名称是 SampleService 托管在端口 20002
  • 您通常可以通过以下地址联系本地服务机构: http://localhost:20002/api/values
  • 集群的公共(public) IP 是 51.140.xx.xx

那么现在您可以通过以下地址联系您的服务: http://51.140.xx.xx:19081/SampleApp/SampleService/api/values (假设您没有保护反向代理端点)

关于azure - 连接到 Service Fabric 应用程序终结点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46360640/

相关文章:

asp.net - 无效操作异常 : Could not find 'UserSecretsIdAttribute' on assembly

azure-service-fabric - 通过 RDP 远程进入 SF 节点

azure - Service Fabric 生产托管

java - 创建 Java Spring Boot 端点以获取 json 形式的对象列表

soap - WSDL 绑定(bind) -soapAction 值

azure - Azure 网站何时应该重新启动?会有什么后果?

c# - 必须在使用 DocumentClient 的 CosmosDB 删除操作中为此操作提供 PartitionKey 值

c# - 使用 MS Word 更新文件时,Azure 存储文件共享会丢失元数据

azure-service-fabric - 如何创建类似表格的可靠集合

wcf - 如何为 WCF 自托管服务定义配置多个端点?