Using ChannelFactory to consume a WCF service
When consuming a WCF service, it is common to generate a strong-typed client proxy class (either through Visual Studio's Add Service Reference context menu item or .NET SDK's Svcutil.exe tool) for invoking service operation. However, there are many cases in which we will need to get rid of this kind of auto-generated service proxy class. For example, we may need to directly reuse the existing types (including the ServiceContract
type and custom data types) used in the service definition, or we might just need a lightweight component to invoke a service operation. For such scenarios, we can use the ChannelFactory
class to directly communicate with the target WCF service endpoint.
How to do it...
Here are the steps for using ChannelFactory
to invoke a WCF service operation.
Define or import the
ServiceContract
types.The first thing we should do is to make sure that the client application has the
ServiceContract
type that is identical to the one used...