title: Connect to Service Fabric application endpoint
body: <p>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: <a href="https://i.stack.imgur.com/lQdCb.png" rel="nofollow noreferrer">running on localhost</a>. 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: <a href="https://i.stack.imgur.com/KIMVS.png" rel="nofollow noreferrer">Service in the explorer</a>. 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:</p>
  
  <pre><code>        protected override IEnumerable&lt;ServiceInstanceListener&gt; CreateServiceInstanceListeners()
      {
          return Context.CodePackageActivationContext.GetEndpoints()
              .Where(endpoint =&gt; endpoint.Protocol.Equals(EndpointProtocol.Http) || endpoint.Protocol.Equals(EndpointProtocol.Https))
              .Select(endpoint =&gt; new ServiceInstanceListener(serviceContext =&gt; new OwinCommunicationListener("", new Startup(), serviceContext)));
      }
  </code></pre>
  
  <p>and my code for OpenAsync:</p>
  
  <pre><code>        public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, StatelessServiceContext serviceInitializationParameters)
      {
          _startup = startup;
          _appRoot = appRoot;
          _parameters = serviceInitializationParameters;
      }
  
  
      public Task&lt;string&gt; 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 =&gt; _startup.Configuration(appBuilder)
          );
  
          var publishAddress = _listeningAddress.Replace(
              "+",
              FabricRuntime.GetNodeContext().IPAddressOrFQDN
          );
  
          ServiceEventSource.Current.Message("Listening on {0}", publishAddress);
          return Task.FromResult(publishAddress);
      }
  </code></pre>
  
  <p>and my ServiceEndpoint:</p>
  
  <pre><code>    &lt;Endpoints&gt;
    &lt;Endpoint Name="ServiceEndpoint" Port="20002"  /&gt;
  &lt;/Endpoints&gt;
  </code></pre>
  
  <p>to sum up my question: how can I acces my Service Fabric applications services in my browser, using swagger and all?</p>