2009年2月10日星期二

Dive deeper...and get stuck

Generally speaking, the deeper you dive into something, the more interests you will get, along with more difficulties. Hmmmm, REST is interesting. After an easy day's work with Netbeans, I turned to .NET for a RESTful service implementation. Unlike the situation in the java world, there're no auto-generation tools to build RESTful services without any pain. WCF is the best choice here, and I have to work from scratch.

To work out a basic RESTful service is not that hard even without powerful weapons. Short after I opened my Visual Studio, my first WCF RESTful service came into being. Then a challenge was raised when I tried to implement another key feature —— the ability to request resource of various kinds of MIME types from one single URI, with the type declaration in the http request header rather than in a query string or to request from another URI.

This feature is so amazing and useful. Simply speaking, it is like when you go to a store to buy a Valentine's hat for your girl, the URI is the hat store, the store sells only one kind of hat. The request is that you're going to buy a hat, the content type you specify in the http header is the packaging style for the gift. Different people get different tastes of decoration, but the hat is the same one.

OK, back to the code. I forgot my supper just to find that there seems to be not enough support to implement the interesting feature under current version of WCF. I've tried to determine the content type of the request in the service implementation code, but failed (even if it were an available option, it would greatly increase the coupling degree between service modules and the http server, not good at all). For a single operation contract in WCF, the server process can only serialize the entities into either XML or JSON, but not both. While REST framework in Netbeans supports both XML/JSON serialization for a single operation contract, by applying a Java annotation @Produces("application/xml","application/json") to the specified contract.

The next is not an end of the story, I'll try to find alternative solutions to this problem or no solution —— a conclusion.

没有评论:

发表评论