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)