Generating a service proxy in code
In most cases, we will create the WCF service proxy types via Visual Studio's Add Service Reference option or the Svcutil.exe tool in the .NET SDK. Both of them actually import the metadata from the WCF service and generate proxy types from it. In addition to these kinds of static proxy generation approaches, WCF also provides powerful a interface for programmatically creating service proxy types.
How to do it...
To generate the client proxy types in code, we need to reference the necessary assemblies and import the proper namespaces. Following are the namespaces that contain those key types for generating the service proxy dynamically:
using System.ServiceModel; using System.ServiceModel.Description; using System.CodeDom; using System.CodeDom.Compiler;
In our sample client application, we will programmatically generate the WCF service proxy through the following steps:
Locate and import the service metadata.
WCF provides the
MetadataExchangeClient
class that...