Search code examples
androidwcfprogressive-download

wcf progressive download


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

Here's what I have so far. This seems to work but its not progressive download. It plays in the android app but only after the whole file has been downloaded.

Service contract:

[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 sources about progressive download, that would be helpful as well. My googling has not turned up much for progressive download + wcf. 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'm setting the data source to a url in path.


Solution

  • so I figured out what was wrong. WCF does do progressive download. I thought the behavior configuration section was necessary when you are returning Streams from your service. But for a webhttpbinding, in order to do progressive download, it should not be set. Setting the binding configuration to streamedResponse will enable chunking and that is not progressive download. Correct configuration is below.

    <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 bindingConfiguration on the endpoint.

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