1

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.

eran otzap
  • 12,293
  • 20
  • 84
  • 139

1 Answers1

2

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:

string svcUri = String.Format("net.tcp://localhost:{0}", port);
ServiceHost host = new ServiceHost(typeof(MyService));
Binding tcpBinding = new NetTcpBinding( );
host.AddServiceEndpoint(typeof(IMyOtherContract),tcpBinding,
svcUri);
host.Open( );
Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • the msdn article seems over complicated , all i need is to assign a value to the address in the endpoint tag i am not creating a proxy on the other side using the svc tool i use the service via a channelfacotry – eran otzap Feb 25 '12 at 14:17
  • I added another link that seems more streamlined – bryanmac Feb 25 '12 at 19:23
  • thanks , i'll post an answer of what i ended up doing simple but not to conventional i'd like to hear your feedback – eran otzap Feb 26 '12 at 07:01