Dynamic Programming with WCF
Update: Please check out the post on memory footprint and dynamic proxy (http://blogs.msdn.com/vipulmodi/archive/2008/10/16/dynamic-proxy-and-memory-footprint.aspx)
Ever wonder what it would like to go from WSDL to code at runtime? Check out my WCF Dynamic Proxy tool that I posted on the wcf.nefx3.com community site. The WCF Dynamic Proxy downloads the WSDL, generate the code, compile the code and then allow you to invoke the web service operations using reflection, all at runtime. Here is the readme from the tool: http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=netfxsamples&DownloadId=3939
The DynamicProxy allows you to create the dynamic WCF client at runtime by specifying the WSDL URI of the service. The DynamicProxy does not depend on the precompiled proxy or configuration. The DynamicProxy uses the MetadataResolver to download the metadata from the service and WsdlImporter to create the contract and binding at runtime. The compiled dynamic proxy can be used to invoke the operations on the service using reflection.
The example shows how you can the dynamic proxy to invoke operations that use simple types and complex types. The flow of usage is as following.
1. Create the ProxyFactory specifying the WSDL URI of the service.
DynamicProxyFactory factory = new DynamicProxyFactory("http://localhost:8080/WcfSamples/DynamicProxy?wsdl");
2. Browse the endpoints, metadata, contracts etc.
3. Create DynamicProxy to an endpoint by specifying either the endpoint or
DynamicProxy proxy = factory.CreateProxy("ISimpleCalculator");
DynamicProxy proxy = factory.CreateProxy(endpoint);
4. Invoke operations on the DynamicProxy
dobule result = (dobule)proxy.CallMethod("Add", 1d ,2d);
5. Close the DynamicProxy