0

I have a desktop client which checks for new content on the server via ASP.NET Web API and saves it locally. something like an email client.

But I don't know exactly what is the best way to implement this, I mean I should have a controller for checking if there is new content, and then client calls another controller for downloading it, or what?

any clues is appreciated.

Blazi
  • 991
  • 3
  • 9
  • 19
  • 1
    What I do in you case it will be to add a header with the last update time, and read only that header from the desktop client - if found different then I go to download the new content. – Aristos Feb 27 '13 at 17:57

2 Answers2

2

The restful approach is described here Returning http status code from Web Api controller you need to take the last updated time into your controller method, use this to check whether a change has been made sice that date, if it hasn't changed then return an HTTP status code of 304 Not Modified and omit the response; however, if it has changed send the resource as normal with a 200 OK.

Personally I would modify the approach mentioned above a bit by managing the last updated via the http headers and etag. That a read of this here for more information.

Community
  • 1
  • 1
Mark Jones
  • 12,156
  • 2
  • 50
  • 62
1

Most people use a polling approach, whereby the app passes in a date or identifier the last time the system checked for updates, then stream any new updates to the desktop client. All you would need to do is call a method that checks the database for updates as of a specific time, stream the new ones, and then add the new ones to the result set (or refresh the entire results).

public class UpdatesController : ApiController
{
   public object Get(long millisecondsAsOf)
   {
     //Query from DB, return  results, or return true/false if there are new records.
   }
}
Brian Mains
  • 50,520
  • 35
  • 148
  • 257