i need to connect 2 instances of the same wcf application to each other (for testing scenario ).
each client exposes a service endpoint and also as the ability to connect to the same service
exposed by his peer .
the end point exposed on each client :
<services>
<service name="BackGammonClient.ClientService">
<endpoint address="net.tcp://localhost:8081/ClientService" binding="netTcpBinding"
bindingConfiguration="" contract="Contracts.Client.IClient" />
</service>
</services>
the problem is that each client exposes the exact same endpoint since they are all running on the same localhost and are given the same port .
how can i dynamically apply a port for each instance of the Client application ?
i was thinking of how i could check if the default endpoint is already taken
and apply some running Port number to attach to the address.
You can programmatically configure your endpoint. See:
http://msdn.microsoft.com/en-us/library/ff647110.aspx
This stack post covers detecting if a port is free:
In C#, how to check if a TCP port is available?
Here’s another link with some programmatic endpoint configuration:
http://en.csharp-online.net/WCF_Essentials%E2%80%94Programmatic_Endpoint_Configuration
So, something like: