Noob WCF/REST question here!
I need to build a simple web service (one method for now), my preference would be for a REST/JSON type of architecture but I’m not sure this can be achieved in my case.
I know that it’s easy enough to serialize/deserialize complex objects into/from JSON while using a REST-based service. Even though I haven’t tested it yet, it also looks easy enough for a REST-based service to return an image.
However, my scenario may need to serve a mix of both. Below is an example of an object definition that can be returned:
class Response
{
string myTitle;
string myDate;
Object myImage;
}
I realize I could store the physical image wherever accessible and then simply return the URL as a string but I would like to avoid the overhead as much as possible.
Is it even possible?
Also note that I’m not committed to REST or JSON in any way, it’s simply that all the cool kids are using it so…
If you want the image as part of the JSON object, convert it into a serializable type. Easiest way is just to use its byte representation.
EDIT: As the OP found, there is a much simpler/quicker way to write: