Be Explicit
WCF WebAPI Preview 4 pains

I’ve switched over to the WCF WebAPI from just vanilla WCF with some fairly bad pains.

1) You’re not supposed to used WCF Contracts with .NET clients.

According to this stackoverflow post WebAPI wants you to use a generic HttpClient instead of a contract.  This, frankly, sucks.  I want .NET clients to use the contract and non-.NET clients to use http straight up.  The only issue has been the trailing slash that the post describes.

I’ve had to hack a IClientMessageFormatter in Silverlight to do JSON properly already with contracts so I just added a bit of code to remove trailing slashes.

2) Caching is on by default

I hated HTTP caching results by default.  Maybe most data isn’t supposed to be very volatile but I can’t really see that being the case.  I’ve had to add in a DelegatingChannel to make each response minimize the caching header on each HTTP response.

3) Objects were being serialized to XML by default.

I had to remove all MediaTypeFormatters besides JSON to get this right.

I’m sure there are better ways to do what I’ve wanted or the code is just incomplete.  I just wish there was more documentation (or stuff that was easily findable.  I’ve done endless googlings) giving high-level guidance.  The best stuff so far is on http://weblogs.asp.net/cibrax/default.aspx

Posted via email from Adam Hathcock’s Life in Software | Comment »