A Useful Dogmatic Way of WCF Service Development

I want to thank Microsoft one more time because they created Windows Foundation Services (WCF).

We must dogmatically use it. :)

I just remembered a day, in one of the training classes…
I said to my teacher “I also want to learn remoting.”
The teacher said “Don’t! There is WCF… ”
I couldn’t see the exact meaning that day.
But today it is shining in front of my eye.
( I am sure it will shine better in the future :p)

While using WCF there is an easy implementation way that I want to share.
With some dependency injection containers you will earn some time …

If you are new to DI and WCF you will earn so much time reading this article.
The dogmatic way uses “Castle Windsor” IOC container.

Here I must specially thank to “Berke Sökhan
for teaching me better software design…
(This thank is bigger than the Microsoft’s Thank :) )

Let’s start the article. A good design is writing your WCF service in 3 layers. Application, Contracts and Services can be your layer’s name endings. Look at this schema first.

This is how my sample works…

It is just a string returning test service…

Contracts Layer has these contracts. An “IMyService” interface for our” DoSomething” Method and a dto class…

Services Layer has MyService class implementing IMyService.

Application Layer is hosting our WCF.

We can install it as windows service or it can host the service working like console application.

This fluent configuration is our WCF configuration… It adds NetTcpBinding, NetNamedPipeBinding endpoints.

To call this service from our web project we need to install it…

This installer uses the NetNamedPipeBinding endpoint to call the DoSomething action…

To use our service from our container. I created a constructor that makes HomeController depending our service.
To understand how this thing works please look into these files. “ControllerInstaller.cs“, “WindsorControllerFactory.cs“, “Global.asax.cs

You can find/download the working solution from this github repo. (github.com/serdarb/DogmaticWcf)

Be Sociable, Share!

    Category: Csharp - C#, WCF - 2 comments »

    2 Responses to “A Useful Dogmatic Way of WCF Service Development”

    1. Tugberk

      Great post but I wonder why you create three separate projects for WCF service unless you will use it for another project.

      You can reduce the build time if you put them under one project.

    2. serdar

      it is a convention that i trust…

      I am adding contracts’ reference to use it …
      Application is hosting my service it must be separate

      please look at this schema again…

    Back to top