Hi,
please help me solve this issue.
I have a client using WCF. I don't want this client to know that it gets its data from a service. I want to use a model like this so I it easier for me to unit test the code and to later replace the implementation of the given interface. The problem with this model is that I'm not able to call close on the ChannelFactory. I'm not sure that I need to call close, but it feels right.
So my question is:
Does anybody know of a good pattern for closing the ChannelFactory when the client only should know the interface of the service? Or is the ChannelFactory closed by it self by some kind of magic?
Below is some sample code that I hope will you understand the question:
static void Main(string[] args)
{
ITestService service = GetTestService();
Console.WriteLine(service.GetData(42));
}
private static ITestService GetTestService()
{
var cf = new ChannelFactory<ITestService>(new WSHttpBinding(), new EndpointAddress("http://localhost:8731/TestService/"));
return cf.CreateChannel();
}
Thanks, GAT