I Want to use WCF Data Service to return mp3 files, along with other data types already served by WCF. Is this possible?
[12/29] I do have the mp3 binary data in sql (~10 seconds each). I'd like to use html audio tag with it:
<audio src="/server/svc/id" type="audio/mpeg" />
Javascript will change the id. Not sure how this will work with WCF returning binary array...
[12/30] It works.... after setting mimetype in CSDL.
Sure, you can do this in three possible ways:
Include it as a binary property on an existing entity (usually the service hosts entities representing each audio file in this case, which would have one of its properties being the actual audio mp3). In code this is just to declare a property of type byte[] (And fill it in). The upside is that this is really easy to setup. The downside is that when you GET such entity the entire mp3 gets downloaded and it's transferred as BASE64 encoded text, so it's big on the wire.
Similar setup as above, but instead of storing the mp3 in a binary property you make the entity a Media Resource Entry, you make it have a default stream value. This is described in this blog post in more detail: http://blogs.msdn.com/b/astoriateam/archive/2010/08/04/data-services-streaming-provider-series-implementing-a-streaming-provider-part-1.aspx and http://blogs.msdn.com/b/astoriateam/archive/2010/09/08/data-services-streaming-provider-series-part-2-accessing-a-media-resource-stream-from-the-client.aspx.
In the latest CTP WCF DS also supports stream properties. Which is similar to #2 above but a single entity can have multiple streams each accessible by its name.
To access the raw value of the audio stream you can use URL (depends on the method you use to expose the stream):
urltotheentity/MyBinaryProperty/$value
urltotheentity/$value
urltotheentity/StreamPropertyName/$value
Note that in #1 the default MIME type of the stream will be application/octet-stream, to change it you need to add an attribute MimeType for the property (reflection provider) or attribute into the CSDL for that property (EF provider). In #2 and #3 the mime type is determined via a call to the stream provider.