Thursday, June 06, 2013

Instrumenting WCF, Extending WCF using IServiceBehavior, IOperationBehavior, and IParameterInspector


WCF has become such a big buzz word in IT solution world, it revolutionary transfers the web services concept to a totally new world, it perfectly implements and extends the Service Oriented Architecture and it also opens the ways to freely design and build flexible solutions.


 My intent was to talk about a very important feature of the WCF and that was extensibility, however, I found a very good series of articles online that talk about extensibility in a very detailed and simple professional way that I can't ever compete with, so I decided to briefly talk about extensibility referring the reader to that great article by Carlos Figueira MSDN blog

 In the lines below I am going to show you how you can extend WFC  in a very simple way using three extending points, and in case you want to know more, you can just read the link above. 

Using the code 
This article requires you to be well-versed with WCF's main concepts like service, contracts, behaviors bindings etc. 

I will build a simple WCF service I will extend the service in three places, or show you how you can extend the service in three places and also show you the execution path by tracing it. Let's start by considering this simple contract:

[ServiceContract(Name = "PasswordGenerator")]
public interface IPasswordGenerator
    [OperationContract(Name = "GeneratePassword")]
    string GeneratePassword();
    string GeneratePassword(int length);

And this implementation:

public class PasswordGenerator:IPasswordGenerator
    public string GeneratePassword()
        return "You called GeneratePassword()";

    public string GeneratePassword(int length)
        return "You called GeneratePassword(int length) overload";

Read more: Codeproject
QR: Inline image 1