1

I'm currently using a WCF web service to return images based on an id:

[WebGet(UriTemplate = "Images/{ID}/{size}.jpg")]
Stream GetImage (string ID, string size)
{
    ... Logic to determine image to return ...
}

If the given ID doesn't exist in the DB, then I return a placeholder image. This placeholder image is always the same.

Is there anyway to inform the client that the image is the same and to cache it, even though the url used to access it is different? It's possible that there could be 30 or more of these placeholder images, so loading the same image 30 times doesn't really make sense.

EDIT:

The answer below works really well. My code looks like this:

{
    WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Redirect;
    WebOperationContext.Current.OutgoingResponse.Location = "//myImageLoc/defaultImg.jpg";
    fileStream = null;
}

This works for img tags and for AFNetworking+UIKit images in iOS.

sflogen
  • 802
  • 1
  • 9
  • 22

1 Answers1

1

You could Place the placeholder image on a url that does not change.

When you get a request that results in the placeholder image, you do not Return the image, you Return a http redirect to the location of the placeholder image.

Since the placeholder is on a static url the Client knows if it has the image or not.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • Good idea, but how would you accomplish that with `WebGet`? – Scott Chamberlain Mar 28 '14 at 16:27
  • This method is working for web. Still need to make sure it doesn't cause any issues in my mobile apps. Thanks! http://stackoverflow.com/questions/992533/wcf-responseformat-for-webget – sflogen Mar 28 '14 at 17:31