In this article, We are going to see how to use Channel factory in WCF.
The channelFactory class is useful when you want share a common service contract dll between the client and the server. In this post I will show how to create a ChannelFactory implementation with message header using WCF.
Let us go through this application step by step
Create a new class Library project->give the name as Interface
In this class library project give the reference to System.ServiceModel.
Its a simple peace of code which consists of Service contract and operation contract.
Now create a console application->name it as service->create a class called EchoService.cs-> give a reference to System.ServiceModel and Interface Class Library.
We get the Guid value in the message header. It takes 2 paramater one as LocalName of the XML header and another as a namespace of the XML.
Now lets go to our Program.cs file and write the service hosting.
Here we are using binding as WSHttpBinding and the endpoint address as http://localhost:8080/Echo.
Just build the application and see if there are any errors.
Now create one more Console app->name it as client->give the reference to System.ServiceModel and Interface Class Library.
In this interface we have given reference to IEchoService and IClientChannel.
IClientChannel->It defines the behaviour of oubound request and reply channel used by client app.
Here we are creating the object for channel factory using wshttp binding. After that we are creating the channel using endpoint address http://localhost:8080/Echo. After that we are creating the Guid and then the Guid value has been added in MessageHeader.
Lets run the application and see the result.
I hope you people like this article.