Dynamically generating a WCF proxy without using a .config file

Recently we had to create a WCF proxy with a common datamodel and serviceinterface, which had to be hosted in several applications (SharePoint, custom .Net services, xRm etc.).

To avoid messing around with various .config-files, we chose to create the WCF-proxy and configuration in code. And all contained in a single project/DLL.

This might come handy some other time and I am posting the code for future reference, so here is how to create a WCF proxy programmatically:

We are using a custom binding, but it might as well be a BasicHttpBinding.

Calling WCF-services using this interface is very straightforward:

Voila. Let me know if you have any questions.

By |2015-02-02T10:14:25+00:00april 14th, 2014|.Net|0 Comments