Feeds:
Posts
Comments

Archive for February, 2010

While testing some web services, I was not-so-pleasantly surprised to find that WCF cannot disambiguate two methods when one is a GET nd the other a POST:

[OperationContract]
[WebDispatchFormatter]
[WebGet(UriTemplate = "/{encodedGameId}?startDate={startDate}&endDate={endDate}&tag={tag}")]
Contracts.Out.Statistics GetStatistics(string gameId, string startDate, string endDate, string tag);

[OperationContract]
[WebInvoke(UriTemplate = "/{encodedGameId}", Method = Verbs.Post)]
void AddSample(string gameId, Contracts.Sample newSample);
[WebDispatchFormatter]

If you leave off any of the query parameters for GetStatistics, WCF cheerfully returns “Method not allowed”. I wanted to make the “tag” parameter optional, and worried this would be a deal breaker.

Fortunately, I came across this WCF post by Ron Jacobs.

The basic idea is to leave off the optional query parameters in the UriTemplate, instead manually pulling them from the current request context. This approach is actually similar to the way you access query parameters in RoR, so I should have thought of doing it like this in the first place.

In fact, if you beef up Ron’s QueryString class, it can clean help you DRY up your code by taking care of data type conversions on the sly.

The moral of the story is that a framework’s design can induce sneaky biases that you only discover as they jump out of the shadows to bite you.

Thanks Ron!

Read Full Post »

Follow

Get every new post delivered to your Inbox.