WCF is fantastic for easy communication between applications. WCF is normally implemented using binding configurations embedded in each application. You usually have configuration for your server, and also your endpoint for your client. I found myself in a situation in which I had no readily available configuration file to use, as well, the endpoint address was dynamic itself based on the application that is consuming this library. Thus, I began searching on how to programmatically setup your client endpoint. Turns out, it is not that hard. Check it out:
In my example, I have created a custom statistics posting service. So, IStatService and StatResults is just the service contract created for must WCF service (these would change with your application). Notice the string passed in indicating the location of the service. This obviously creates a BasicHttpBinding configuration only, but you should be able to alter any of your standard WCF Configuration settings programmatically here too (make sure they match the service though J). With this above implementation I have NO config file (and the endpoint address is passed to this code – not hardcoded as shown above).
var channelFactory = new ChannelFactory(binding, endpoint);
Does not seem to work. Says that cannot create an instance of the abstract class.
Thanks for the post -it’s helpful. Note that new ChannelFactory is a generic and requires a type reference, e.g., ChannelFactory(…)
Thanks for the post and it works with :
var chnannelFactory = new ChanneloıFactory(binding,endPoint)