0
votes

I have set up a Service Fabric cluster on Azure, and have an application with 2 services running. now I want to be able to connect to the services in my browser, like I can when I run it on localhost. The application uses Owin and Swagger. Here is how it looks like running on localhost: running on localhost. When I try to connect to it from Azure, I get a timeout error. I'm using port 20002 and 20001 in the application, and I have opened the ports when I set up the cluster (port 19000, 19080, 20001 and 20002 are open in my cluster). Here is my service in the Explorer: Service in the explorer. The cluster is setup with certificate security, and I have the certificate added to my browser (I'm using it to connect to the explorer). My code for 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)));
    }

and my code for 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);
    }

and my ServiceEndpoint:

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

to sum up my question: how can I acces my Service Fabric applications services in my browser, using swagger and all?

1
Forward an (any) external port to internal port of 20002 on your load balancerMardoxx

1 Answers

2
votes

The best way is for you to use the reverse proxy on port 19081. You have to enable it at cluster creation state.

You then have to set up the load balancer rule for reverse proxy. The basic set up of a service fabric on Azure load balancer does not have rule for TCP port 19081 however you can copy the rule of 19000.

After that for example:

  • Your application name is SampleApp
  • Your service name is SampleService hosted in port 20002
  • You normally reach your service locally at http://localhost:20002/api/values
  • The public IP for your cluster is 51.140.xx.xx

Then now you can reach your service at http://51.140.xx.xx:19081/SampleApp/SampleService/api/values (presume you dont secure your reverse proxy end point)