Windows Communication Foundation (WCF) is The One Way to implement inter-process communication on the .NET platform. Well, it’s not really the only way, but it’s certainly the most common way. It’s a bit misused. Unfortunately, WCF suffers from numerous problems. It is extremely configuration heavy, it has known design issues, and it has a learning curve that nearly rivals Lisp. We need a better way to handle inter-process communication in the .NET world. I’m not proposing a solution in this post, merely throwing out some ideas. Feedback is welcome in the comments!
What is Windows Communication Foundation?
From MSDN:
Windows Communication Foundation (WCF) is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.
Basically, WCF is a highly-configurable API for communication to/from services. It’s the successor to both ASMX Web Services and .NET Remoting. It has several advantages over both technologies, not the least of which is the separation of the “contract” from the implementation. It’s quite useful for building loosely-coupled, standards-compliant end points.
What’s wrong with it?
Configurability adds complexity, and WCF is very configurable, making it very complex. There are tools written around managing the app.config entries that it requires. You can choose to configure WCF via code, but this is not the recommend approach, and it’s still more complicated than it should be.
WCF also suffers from some pretty serious design issues. For whatever reason, even as we have reached the second major .NET revision since WCF was introduced, the WCF “dispose” semantics remain broken.
The “proxies” themselves are another problem with WCF. They look exactly like a normal class. If you hide them behind an interface reference, the fact that you are dealing with a proxy object can be totally obscured, leading to poor implementation choices downstream. While this is certainly convenient in terms of cranking out code, the drawbacks can be severe. Imagine how the following will perform if the IDataSource instance is actually a proxy for a remote object instead of a local object.
public void ListResults(IDataSource source, int count) { for (int i=0; i < count; i++) { //This is what we'd call a 'chatty' interface... Console.WriteLine(source.GetItem(i)); } }
In a nutshell, I’d summarize WCF as a tool that tries to solve every problem but only manages to become too complicated to effectively solve much of anything. It tries to make a complex problem (inter-process communication) simpler by masking it under layer upon layer of abstraction. This is exactly the same approach that ASP.NET WebForms took. Does it work some of the time? Sure. But most of the time it causes far more pain than it prevents.
What should be done differently?
I think attempting to create a single, unified API that can solve every problem via reconfiguration is a really bad idea. With WCF we can configure every single aspect of the end point, the transport, the channel, etc. There are defaults for many things, but even using the defaults where possible won’t get your configuration much below 20 lines of app.config mess.
Instead, I would like to see specialized APIs to tackle each type of problem. (We’re already making a little progress on this front with things like NServiceBus, which provides an API that is tailored to the types of problems service buses are meant to solve.) Instead of requiring extensive configuration, the APIs should adopt intelligent (but swappable) conventions, allowing users to get up and running with the API with near-zero configuration while still providing plenty of hooks for extensibility. I think sacrificing some flexibility in order to avoid complexity is a good trade.
Another problem: right now, I’d say that making synchronous calls is the path-of-least-resistance when using WCF. Sure, WCF supports asynchronous calls, but I think most developers fall into the easy trap of making synchronous calls. I think the remote APIs should be asynchronous-by-default. It should take (some) extra work to make synchronous inter-process calls, thereby redirecting developers towards a better design for their distributed systems. Making synchronous web service calls is a good way to kill your system’s performance.
One common use case I keep bumping in to is making a Remote Procedure Call to a service on another physical machine. Handling that with WCF requires extensive configuration on both ends. I’m not sure exactly what I’d like to see on the server-side, but perhaps something like this (inspired by StructureMap):
public class MyServiceObjects : ServiceRegistry { public MyServiceObjects() { //This would load default conventions for things like //channel and endpoint settings, but it could be replaced //by your own conventions. With.DefaultConventions(); //By default, expose services over a TCP channel Expose<IDataSource>().Using<ConcreteDataSource>(); //Changing to an alternate channel should still be trivial. Expose<ICommandableThing>().OverHttps().Using<ConcreteCommandableThing>(); } }
Note that there are no app.config settings needed for this. All the configuration data would come from the conventions (defined in code) or would be explicitly specified in the registry. Are there downsides to this? Sure: I can’t decide to change how my services are exposed without recompiling my application. I don’t see that as being a big loss.
Client-side, I think it should be very clear when you are using a remote object. The remote object should not pass for a local one (at least not without having to jump through a small hoop; after all, there are going to be times when treating it as a local object makes perfect sense). The proxy should be asynchronous by default and support batching remote calls. Here’s what my previous example might look like with such an API:
public void ListResults(string remoteSourceUrl, int count) { var proxy = RemoteProxy.For<IDataSource>(remoteSourceUrl); using (proxy.BeginBatch()) { for (int i=0; i < count; i++) { //The first lambda is the call on the data source. //The second lambda is the callback to run when the //remote call completes. proxy.Call(ds => ds.GetItem(i), item => Console.WriteLine(item)); } } }
So what do we do?
I’m not sure. Microsoft has shown no real hint of backing off from WCF despite the overwhelming negative feelings that most of the .NET community has about it, but I don’t see a lot of effort by the community to develop alternatives aside from the various service buses. Maybe I’m overlooking something (if so, let me know). I’d love to work on something like this, but my workload is already overwhelming me. If there’s an effort by someone out there to implement something along these lines though, I’d be game for helping out when/where I can.
Cheers for the great info m8
Real ID law must be Tea Party Identity Lunacy
Excellent!! Loving your posts. Keep it up!.
Nice post! Do you have an RSS Feed for your blog that I could subscribe to?
great post, thanks. theres great stuff in this blog
I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful.
I was very delighted to find this site.I wanted to thank you for this brilliant read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out new stuff you post.
Man oh man – you really opened up my eyes! Try-Catch-FAIL – Towards a better Windows Communication Foundation was a wonderful read. The Internet has so much information, I get so caught up in so many different directions, it so hard to figure it all out. Thanks again for the post!
As always ur posts are very helpful.
Blogging is the place where one can easily express his thoughts, wishes and ideas about his interested niche to so many people.
Great post I must say.. Simple but yet interesting and engaging.. Keep up the good work!
Hi,
I have been read and following your site for 3 days and now I starting to like your post.
I feel enjoy to read your article.
Thanks
Hi HI First time on Try-Catch-FAIL – Towards a better Windows Communication Foundation bounded here on your site, founde on Google. gyzgyn hot Send me news to [email protected]
You’re a great writer. That was an well thought out post.
Digged, nice read
I wanted to thank you for this great read!! I definitely enjoying every little bit of it smile I have you bookmarked to check out new stuff you post.
Nice website, I recently came across it and I’m already a fan. I just got rid of 30 pounds in thirty days, and I want to share my weight loss success with as many people as possible. If I can lose the weight then any one can. No matter what you do, never quit and you WILL attain all your weight loss ambitions!
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
Targeted traffic is important because it brings people to your blog who are interested in the topic.
This is a single of my favorite sites in the world for its details. This internet site was pinged by http://viralsubmitter-pro.com/review/ […]
I just couldnt leave your website before saying that I really enjoyed the quality information you offer to your visitors… Will be back often to check up on new stuff you post!
Great post! I am just starting out in community management/marketing media and trying to learn how to do it well – resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case.
Ran across your blog on Google. Interesting points. Don’t leave it there. When can we expect more?
Hey mate, when browsing at your site i see some sort of weird codes all over the page, in case it’s important I just thought I’d let you know it says this with all sorts of other stuff after it: “Warning: Cannot modify header information – headers already sent in wp-settings.php line 12?
Hi great site mate, ive got a error php 12? probley nothing
The hardest decisions to make are when that unthinkable thing happens and one of your friends die Cremation Urns are a popular choice to help remember those who have passedOne of the first choices you will make depends on who it is for there are many different types, styles and categories of Urns. Some of most common materials Cremation Urns are made of are Brass Urns, Bronze Urns.
Nice!Just bookmarked this website, i’ll be back here once again.Love Try-Catch-FAIL – Towards a better Windows Communication Foundation
Hey very nice blog!! Man .. Beautiful .. I have bookmarked your blog also…
Great blog!I added it to my bookmark so i can visit it once more.Love Try-Catch-FAIL – Towards a better Windows Communication Foundation
Yes it is nice information but I also need some info about free marketing sites please let us know
This is one of the most great blogs Ive read in a very long time. The amount of nice information in here is stunning, like you practically wrote the book on the subject. Your blog is good for anyone.
What is Chennai Web Directory about? Chennai Web directory is the only web directory featuring large collection of websites servicing Chennai and Tamil Nadu. They display websites of all categories which helps you to find the details about a product or service without asking your family, friends, neighbors, relatives, etc. http://www.all-health-dir.com.
Yes this is one of the most great blogs Ive read in a very long time. The amount of nice information in here is stunning, like you practically wrote the book on the subject. Your blog is good for anyone.
Thanks for such interesting writing on the Internet as I have been able to find here. I agree with most of what is written here and I’ll be coming back to this site again. Thanks again for publishing such great reading material. <a href="http://www.findmesomeone.org">Friends‘ site</a>
I do not accept as true with all on this post, but you do make some good points. I am very excited about this subject and I myself act alot of research as well. Either way it was a well thoughtout and great read so I figured I would leave you a remark.
Dublin is 10/1 to win the 2010 Kentucky Derby according to oddsmakers from online sports book BroburySports.com. Lookin at Lucky is the favorite to win at Churchill Downs this weekend at 2/1, while Sidney’s Candy has opening odds at 3/1. While Dublin has finished in the money in each of his last three races, he’s lost to a couple of notable Kentucky Derby contenders. Line of David (20/1) and Super Saver (10/1) beat him at the Arkansas Derby, as did Lookin at Lucky and Noble’s Promise (10/1) at the Rebel. Conveyance, who has 18/1 odds to win the Kentucky Derby, beat Dublin in the Southwest.
This is a nice idea how to do such a thing. Cool place to find. Best wishes.
Nice blog! Are you using Blog Engine as your main blogging platform? I am asking this question because your blog looks a a little different than other blogs I visit.
Great post. I put you in RSS now so I can read more from you sometime again.
There are some quick and easy cooking recipes on this website .
Excellent site
Hi buddy, very informative post. Please keep them coming.
Great Post. Niftier then the simillar post I checked yesterday on WordPress. Maintain the good work.
great post, thanks. theres great stuff in this blog
Does this page load slow for everyone else, its only this page? Thanks for the post.
When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get four emails with the same comment.
I study logistics business in Brazil and I love this area
Nice post. You’re in google rss reader now so I can read more from you down the road.