Scott Hanselman

Basically I want something like the following to work public class BookService RestService RestMet

November 12, 2002 Comment on this post [0] Posted in Web Services | XML
Sponsored By

Basically I want something like the following to work -

 public class BookService : RestService 
{
[RestMethod(Verb="POST", Uri="something")]
public XmlNode MethodOne(string uri, XmlNode input) { }
  [RestMethod(Verb="GET", Pattern="/book/**")] 
public XmlNode MethodTwo(string uri) { }
  [RestMethod(Verb="GET", Pattern="/order/")] 
public XmlNode MethodThree(string uri, NameValueCollection queryString) { }
}

So for MethodOne, only POSTs to the URI "something" will be dispatched to it. And since it has an XmlNode as a parameter, I would check the content type of the incoming request. If it is text/xml (or one of the XML variants like application/soap+xml), I will load it and pass it in.

For MethodTwo, only POSTs to the URI /book/ and all the sub-URIs underneath book will be dispatched to it. Nothing is passed in by default. That does not mean you can't get access to the information. You can get access to the stuff through the Current HttpContext or the helper properties you inherit from RestService.

Finally for MethodThree, it is similar to MethodTwo except that the parameter it takes is NameValueCollection. This is just for convenience. The framework will pass in the query string directly. If MethodThree happened to want handle a POST, then the NameValueCollection would be a combination of Form variables as well as query string. I'm debating whether or not to make that configurable through an attribute. 

[News from the Forest]

This will be pretty slick when Justin gets it done...I'm looking a lot into how to implement REST on .NET, as well as how a Message Broker would look for a more SOAP-y document-y world looks.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.