Frage

I currently have a netTcpBinding endpoint that is listening on port 8000.

I have configured the base address in the app.config file like so

net.tcp://*:8000/TestProject/Service

This works as expected and the service listens on port 8000.

My issue is that this service will be deployed on third-party machines and I am concerned about port collision (and experiencing System.Net.SocketException when trying to open a port that is already in use by another application).

I can handle the exception and use IPGlobalProperties to find an available port in code to recreate the base address using a free port but I was hoping there was a way to instruct WCF to use a dynamic port in the app.config setting.

The client connections do not need to know a predefined port number as they use WS-Discovery to find the server endpoint.

War es hilfreich?

Lösung

You could add this in your app.config.

<appSettings>
   <add key="Port" value="8000" />
</appSettings>

And read it out in the code

string port = ConfigurationManager.AppSettings["Port"];

After you read the port in you have to create the url.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top