Let's say I am using the new WCF Web API to build a RESTful service and, in my service, I have a section of the URI that will describe the target resource, but is used on (nearly) all methods of the contract. For example, if I have a User service that deals with eCommerce and may look like:

If I have to continually load the organization and test for null, this will bog down my code and is not very DRY. (So tempted to spell out DRY...) What I would like to do is load up a property in the MyUserService class that is populated when {OrganizationName} is included in the URI and throw a WebFaultException otherwise. Because this is apart of the URI, what would be the best way to accomplish this?

EDIT:

For those that may be interested, here is an example of the HttpOperationHandler I came up with. There doesn't seem to be a whole lot of information out there covering this. I also found more information about Processors that will be coming with the WCF Web Api suite and it looks like they will handle this sort of thing better replace HttpOperationHandlers and it seems they may be easier to use. (This is just a for-instance to cover some things I found hard to find. I wrote it up a bit differently in my application.)

Processor is just the old name for HttpOperationHandler
–
Darrel MillerMay 21 '11 at 0:56

@Darrel Miller - thanks! I am trying to keep up with all the changes and the lack of information (understandable) that also mixes in with other "WCF REST" links makes it pretty tough. Thanks for catching this!
–
Jim D'AngeloMay 21 '11 at 0:59

The project has been out in the open since very early days, so there is lots of out of date documentation and blog posts. Now that the library is starting to settle down things should get better.
–
Darrel MillerMay 21 '11 at 1:00

Thanks! I agree it should get better with time. That's why I wanted to post the solution I came up with just to add to the confusion! =D (Thanks, too, for fixing the tags.)
–
Jim D'AngeloMay 21 '11 at 1:02

1 Answer
1

This is exactly what OperationHandlers are for. You create a single OperationHandler that converts the URI parameter into a strongly typed object that you can just accept as a parameter on the operation.