Posts Tagged ‘REST’

Hosting WCF REST in IIS

November 15, 2009

Hosting a WCF REST service in a console og windows application is made extremely easy by magic that is auto configuration, provided by WebServiceHost. Modifying the standard WCF Service Application Project on the other hand is a little harder as it makes you deal with the horror that is XML configuration 🙂

Since this isn’t the first time i find my self searching for the correct way of setting things up, i thought i would throw in a link:

http://blogs.microsoft.co.il/blogs/smallfish/archive/2008/12/30/how-to-configure-wcf-rest-service-hosted-in-iis-properly.aspx

Streaming MP3 audio from a WCF REST service

June 29, 2009

For a project i am working on in my spare time, i needed to stream MP3 audio from a REST service, implemented in WCF. I was supprised at how easy this was. It’s as simple as setting the response content type and returning a stream:

IAudioDemoService.cs method definition:

[OperationContract]
[WebInvoke(
Method = "GET",
UriTemplate = "/AudioStream")]
Stream GetAudioStream();

AudioDemoService.cs method implementation:

public Stream GetAudioStream()
{
	WebOperationContext.Current.OutgoingResponse.ContentType = "audio/mpeg";
	return new FileStream(@"c:\AudioFile.mp3", FileMode.Open);
}

(actually the content type isn’t strictly nessesary, but it enables a client to identify the information in the stream – a browser for instance might use it to select an appropriate application for processing)

Easy!