blog tag

A Testable WCF Wrapper

Description: A Wcf Wrapper that will properly disposes of wcf resources
Publish Date: 09/06/2015
Keywords: WCF C# WCF Wrapper

A Testable wcf Service Wrapper

Problem

Calling a wcf service requires some setup and tear down when done properly.

Solution

This code wraps the wcf call and takes care of closing and aborting the wcf client and channel factory. It also finds the configuration element automatically by the full name of the wcf interface. Note that you usually have to add the full namespace to the interface in the binding contract attribute for this code to work properly.

Background

https://msdn.microsoft.com/en-us/library/aa355056%28v=vs.110%29.aspx

http://blogs.msdn.com/b/jjameson/archive/2010/03/18/avoiding-problems-with-the-using-statement-and-wcf-service-proxies.aspx

https://msdn.microsoft.com/en-us/library/ms733912%28v=vs.110%29.aspx

https://msdn.microsoft.com/en-us/library/ms734681%28v=vs.110%29.aspx

Source Code

VS2013 Source Code

The Service Wrapper Class

Example Usage

Service Wrapper Tests. This also has some cool sytax from NSubstitute and Fluent Assertions.

I got to try out Jet Brains Dot Cover on this project. I'm really liking it!

Dot Cover Results

Comments: 3
Paul Roe (09/08/2015)

Nice wrapper brother, how are things?


Allan Chadwick (09/09/2015)

Hey guys! Ya, this code might look slightly familiar.. lol.. I'll bet Mario has a better version already rocking in the new code base!


Mario Hines (09/08/2015)

Very nice work.


© Chadwick 2021