Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Saturday, September 12, 2009

WCF and REST

I'm on a project that was using WCF and we've managed to make the transition to using REST (well, to be honest so far its just POX).

REST is a joy and I really find it such a pleasant experience compared to RPC let alone WS-*.

However WCF and REST just are not good bed fellows. Some of the problems are that it doesn't support linking out of the box, content negotiation isn't there, no support for common HTTP/REST patterns, it limits the design/granularity of your resource handlers (think MVC controllers), and the REST starter kit (at least when I looked at it) was appalling.

There are also lots of annoyances that you only discover when you come to use it and unfortunately, as Seb discovered when he developed our REST framework on top of WCF, WCF lacks some key extension points meaning you end up having an extremely painful time getting the functionally you need.

The point of this post isn't to beat up on WCF, its just to make you aware of the issues. If all you want to be able to do is a bit of simple CRUD then you might find WCF to be a good solution, however just be aware that it isn't designed to scale out to handle more interesting problems or more RESTful solutions.

On the bright side the WCF team did contact me and Seb and we did give feedback which apparently will feed into a release post-WCF 4. My feeling is that if they don't make massive improvements then WCF will lose out on the REST battle, especially as there are some great REST frameworks appearing in .NET-land.

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone

Sunday, May 10, 2009

Book Review - RESTful .NET

Since we are using REST on top of WCF on my current project I was glad to see that this book had been written as I was hoping it would answer some questions I had.

However my first issue with this book was the title. As I say we're using WCF but WCF isn't the only way to implement REST in .NET, however the book does not take the time to evaluate alternatives (including building RESTful applications on top of ASP.NET MVC) so RESTful WCF would have been a more accurate title.

In fact if we wanted to truly represent the books focus I think we would call it WCF REST because the primary focus is on WCF. There was a lot of WCF detail in here, starting from chapter 2, and personally I found some if quite boring especially where the author has chosen to put in property listings of some key WCF classes. I just don't find that sort of content all that useful and I'd have expected a lot of it to be in an appendix at best.

However the WCF focus has some other implications. Take HATEOS which is an important part of REST, my company has been lucky enough to have Sebastien Lambla and Alan Dean in our office and both emphasized its importance. However there is almost no discussion of it in the book, and the reason for this becomes clear on page 246 where the author states that although hypermedia is important in REST it isn't covered in the book because WCF has poor support for it. As I say we're using WCF so I knew that WCF's support for links in normal representations was non-existent, but I do consider it a flaw of the book and in my view the author would have been better stating this big problem up-front or tried to add framework to make linking a lot easier (something Seb did for us).

Strangely the author actually states that he actually avoids discussing custom infrastructure code because it takes away from learning about the technology (page 97). Personally I would prefer the book if had a focus on REST and how to get the advantages of REST using WCF, low level WCF plumbing/architecture is a necessary evil not something I want to read much about and more importantly if we need extra framework then I'd like to see it discussed.

I also thought it was doubly odd that chapter 9 discussed "Using Workflow to Deliver REST Services", all centred around Windows Workflow, when to me when I see the words workflow in a REST book I'm again thinking of HATEOS (the RESTbucks example at InfoQ shows this approach brilliantly and will form part of a rival book).

Before wrapping up I also wanted to identify one bit of the book where the advice is very questionable. Chapter 10 is called "Consuming RESTful XML Services Using WCF" and one approach described is to take the interface attributed with ServiceContract and use it client side. Just to be clear we're talking about making class like channel.CreateAuthority(authority) and then letting WCF work out what HTTP request to make. You won't want to be doing that.

Anyway I personally wouldn't recommend this to anyone wanting to learn about REST, instead I'd recommend (for now) RESTful Web Services. If however you are using WCF and REST, and feel you already understand REST, then this book will give you some insight into support for REST in WCF.

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone

Tuesday, October 28, 2008

Biztalk and WCF - When two big beasts collide

I spent the entirety of last week trying to create a ridiculously simple Biztalk orchestration and trying to get it to talk to a simple WCF service and I thought I should describe what I "learned".

Biztalk

If you follow me on Twitter you'll know how unbelievably annoyed the results made me and although I didn't learn much from the experience I thought I should put down some tips:

  1. If Biztalk gives you an error DO NOT read it, the message itself is bound to be utter jibberish and the correct response is to put it straight into Google.
  2. If Biztalk behaves like a problem is with step N don't assume that step N-1 passed especially if step N-1 is a transformation. You can test the transformation in isolation within the IDE using a sample document so do it,
  3. If you are having real problems working out why Biztalk and WCF aren't playing ball then it might well be XML namespaces that are the issue.
  4. If you're thinking of renaming the orchestration or anything in it be careful and take a backup first.

WCF

Whilst Biztalk left me cold the WCF side of it was a joy, mainly because Johnny Hall pointed me at the Castle WCF Facility and his own usages of it. Using the WCF Facility configuring your services is an utter joy, definitely when compared to the XML based approach that you get with bog-standard WCF. The documentation isn't great but the tests that you get with the Castle source code are the real way to see how to use its fluent interface.

Johnny also suggested we use a console application to host the service when testing and a Windows Service when deploying for a real. The console application makes testing locally a lot easier, just CTRL+F5 and your host is loaded and ready for you to fire requests at it.

If only Biztalk was as enjoyable to use...

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone

Sunday, July 06, 2008

WCF/Silverlight/IIS7 Configuration Links

I've just wasted 4 more hours getting my simple Silverlight/WCF play area setup.

I had lots of problems and although the answers were out there on the Web they were difficult to find, especially as SL/WCF seemed to be returning bog standard exceptions every time something failed. In particular I got sick of seeing "The remote server returned an unexpected response: (404) Not Found."

So here's a list of links that you might find useful if you are planning to play with SL.

Silverlight Links for Resolving Errors

Although google search was the main way I got answers I did find these sites useful:

  1. Forum - Plenty of gotchas and bugs in there to catch you out, solutions to my issues were available on here though.
  2. Irritated Vowel - Had some answers to issues I had, including cross-domain issues when calling WCF services.
  3. Tim Heuer - Looks like he's got answers to lots of issues you'll have.

Silverlight Config

If you are making cross domain requests ensure you have "clientaccesspolicy.xml" and/or "crossdomain.xml" setup and be aware that the required formats of these files is different in beta 1 and beta 2.

You may also get a ProtocolException (404 not found) when you try to call a WCF service. Cross-domain calls is one reason for this but another is that your WCF service is not setup for basicHttpBinding. You can read more on the forum or in Building WCF Services For Consumption From Silverlight. This page made me realize I needed to update my service reference after changing the binding. Lastly this forum entry pointed out that for it to work you need to specify that you want it to create a Website project to host the SL app.

Oh and you will also find that when you add a "Service Reference" to the WCF service you'll find that the "ServiceReferences.ClientConfig" is incorrect.

IIS7

I switched to using IIS 7 rather than the development server because I was having so many issues but to get my app within IIS7 I had to follow some of the steps here (important bit for me was setting it up for ASP.NET).

I then got an error containing the message "could not download the silverlight application". Turns out it was because the MIME type was not registered and the solution is to combine what is in this article with what is in this one (second one is more relevant).

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone