Wcf progressive download

I am trying to write a WCF service that can send mp3 files to a client. I need it to transfer the mp3 file using progressive download, because the client is an android application, and I want it to start playing as soon as possible. How to make progressive download using WCF? Is it possible?

Here is what I still have. This seems to work, but not progressive download. It plays in the Android application, but only after the entire file has been downloaded.

Service Agreement:

[OperationContract, WebGet(UriTemplate = "/GetFileStream/?filepath={virtualPath}")] Stream GetFileStream(string virtualPath); 

Service Configuration:

  <bindings> <webHttpBinding> <binding name="streamedHttpBinding" transferMode="StreamedResponse" maxReceivedMessageSize="1000000000"> </binding> </webHttpBinding> </bindings> <service name="..."> <endpoint address="" behaviorConfiguration="restful" binding="webHttpBinding" bindingConfiguration="streamedHttpBinding" contract="..." /> </service> <behaviors> <endpointBehaviors> <behavior name="restful"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> 

If you can provide links to gradual download sources, this will also be helpful. My googling is not too much for progressive download + wcf. I appreciate your help.

Android Code:

 player.reset(); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player.setDataSource(path); player.prepare(); player.start(); 

player is a MediaPlayer object. I set the data source to the url along the way.

+4
source share
2 answers

so I understood what happened. WCF does progressive loading. I thought a behavior configuration section is needed when you return Streams from your service. But for webhttpbinding to do progressive loading, it should not be installed. Setting the binding configuration for streamedResponse will allow chunking , and this is not a progressive download. The following is the correct setting.

 <bindings> </bindings> <service name="..."> <endpoint address="" behaviorConfiguration="restful" binding="webHttpBinding" contract="..." /> </service> <behaviors> <endpointBehaviors> <behavior name="restful"> <webHttp /> </behavior> </endpointBehaviors> </behaviors> 

Note that there is no Configuration binding on the endpoint.

Thanks @MisterSquonk for your comments. they helped me look into the right places.

+2
source

See my answer to this question here Developing a streaming server for Android , which basically describes just using IIS as a server to β€œopen” (and gradually stream) mp3 files using AsyncPlayer on Android (the same thing works for MediaPlayer).

Also see my answer to the question here How to communicate over a local area network between a C # desktop application and a mobile (Android) device? , which describes a simple HTTPListener 'service' written in C #. It can be used for a variety of things and can be adapted to open an mp3 file that MediaPlayer could stream.

Just some alternative ideas for WCF.

0
source

All Articles