A Testable WCF Wrapper


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

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):

Name: Paul Roe
Comment Date: 9/8/2015
Comment:
Nice wrapper brother, how are things?


Name: Allan Chadwick
Comment Date: 9/9/2015
Comment:
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!


Name: Mario Hines
Comment Date: 9/8/2015
Comment:
Very nice work.


Leave a Comment:




    Captcha Challenge