As explained in What are those SOAP/RPC and XML/REST styles ?, the REST support in Silverlight has several limitations :
- Only the “Content-Type” HTTP header can be accessed from the Silverlight client code.
- The WebClient works fine in most scenarios, yet turn to HttpWebRequest if you need to control the response flow.
- HTTP methods are limited to POST and GET (no PUT, nor DELETE support) – see below
- You may encounter Browser Caching issues – see below
1. Manipulating a REST service model is done via 4 basic HTTP methods: GET, POST, PUT, DELETE . The last two methods are not yet supported by Silverlight :
You request data from a REST service by invoking a URI with the WebClient class. As all service communications are async in Silverlight, you process the result through an handler.
1: WebClient client = new WebClient();
2: client.DownloadStringCompleted +=
3: new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
4: client.DownloadStringAsync(new Uri(“http://foo.org/service/items”));
You may experience that the same data gets always retrieved, even when modified on the service side. To solve this problem :
- either set the Cache Control with “no-cache” value on the service side,
- or ensure that subsequent calls are made with differents URI (so that the results do not get cached). This is mandatory if the REST framework on the service side does not support cache header customization, as it is the case for the Restlet framework (as of July 2008, Jerome Louvel is working on it).
client.DownloadStringAsync(new Uri(“http://foo.org/service/items?cache=” + DateTime.Now));