Restful WebServices

posted in: Uncategorized | 0

BronwenWeeGo.jpgSo lately I’ve been converting some SOAP WebServices to Rest webservices.  There’s lots of papers on REST but atm there’s no real standards, just guidelines.  As far as i can tell, it’s just passing data using HTTP.

So if i have an existing webservice here: www.SoulSolutions.com.au/MyService.asmx with a method called GetPoints i’d want to call a method “GetPoints” in rest as www.SoulSolutions.com.au/MyService/Rest/GetPoints
and i can either pass the params in the query string or the request header/body.  I’ll go with header just for the fun of it.

Cause i just want to use the existing names, I’ll won’t user GET, PUT, and DELETE to determine the action of my method..but that’s just me being lazy

So these are the steps i took to build a restful web service…

1. Put all the common code into a class that both webservice and rest can call
2. Write a http handler called SoulSolutions.RestHandler
 Using reflection…
 It’ll load up the current assembly, and my common class.
 It grabs the name of the method from the request and validates it exists in the assembly
 Grab the parameter info and validate we have the right params and they’re the correct type etc
 Call the method and return the result…either as a text value or xml..
 
3. add the handler to my existing webservices project, and only pick up calls with a rest path

    <httpHandlers>
      <add verb="*" path="rest/*" type="SoulSolutions.RESTHandler, SoulSolutions" />
    </httpHandlers>

Improvements to this I’d like to make later…
Add some custom attributes to mark the logic classes as “Rest Classes” and mark the method within them as “Rest methods” for a couple of reasons…
1. We may split up the classes later and this will make it easy to find the valid ones
2. For the methods, we may only want to support a subset of methods for rest and we can add a methodname attribute if we want to rename what the user calls without changing the name of the underlying function.

Do some performance testing to see if i need to add some custom caching for the reflection

Later on i can put some logic to map a HTTP DELETE for a method Point to the function DeletePoint, GET to GetPoint, PUT to AddPoint etc