In the endpoint configuration for a service in ServiceManifest.xml file, visual studio typically creates following information:
<Resources>
<Endpoints>
<Endpoint Protocol="http" Name="ServiceEndpointHttp" Type="Input" Port="8304" />
</Endpoints>
</Resources>
If I remove Port attribute and its value (as shown below),
<Resources>
<Endpoints>
<Endpoint Protocol="http" Name="ServiceEndpointHttp" Type="Input" />
</Endpoints>
</Resources>
the service fabric run time will assign a dynamic port to this service.
Since all ports are automatically blocked by the related load balancer, how do I configure the load balancer so that service can be accessed from outside?
You could update the Azure Load Balancer for every service, but as the ports are dynamic, that's not a good idea.
It better to use a Reverse Proxy, e.g. the built in reverse proxy for that. It will receive all incoming calls (on a fixed port, like 80) and forward them to HTTP endpoints within the cluster.
Because endpoints are registered internally with the Naming Service, the built in Reverse Proxy can find them.
You can also build a proxy yourself and use FabricClient.QueryManager to resolve service endpoints.