WCF REST Image Service

Thanks to Penmetsa, Chaitanya for researching this solution.

Example below returns the image from a file stream in WCF REST

 

[WebGet(UriTemplate = "/GetImage?ImageId={ImageId}")]
    public Stream GetImage(int ImageId)
    {
        FileStream stream = null;
        if (ImageId == 1)
        {
            stream = File.OpenRead(@"C:\Images\Ipad.jpg");
        }
        else if (ImageId == 2)
        {
            stream = File.OpenRead(@"C:\Images\Iphone.jpg");
        }
        else if (ImageId == 3)
        {
            stream = File.OpenRead(@"C:\Images\Macbook.jpg");
        }
        WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
        WebOperationContext.Current.OutgoingResponse.Format = null;
        //var memoryStream = new MemoryStream();
        //stream.CopyTo(memoryStream);
        return stream;
    }
Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: