Reputation: 60724
I have a WCF service that is part of a mesh like network. That means there are 10+ machines exposing the same service, but all of these machines also need to connect to the other machines to retrieve data. So that means that the application both expose the service, and also connect to the same service on other machines.
Currently, I have added a service reference to the service inside the program, but it seems like quite a waste since the program is the service. That means I have basically created a service reference to itself, and I have to update this reference whenever I change something.
Any way I can get around this, and use the service without adding the service reference?
The problem is that without the Service reference, I don't have the proxy class that I use to set up the service. Currently, to connect to the service on another machine, I use code like this:
var client = new MyServiceClient(binding, otherMachineEndpointAddress);
//call some methods on client
If I can replace this part of creating the service client, to connect to the service and call my methods, the application will be greatly simplified.
Any ideas?
Upvotes: 1
Views: 530
Reputation: 60724
I tried to find the answer for a long time, but after posting this question I found out how to do it, and it was really quite easy all along.
I replaced the code mentioned in the question with this
var client = ChannelFactory<IMyService>.CreateChannel(binding, otherMachineEndpointAddress);
//call some methods on client
Worked as a charm ;)
Upvotes: 1