开发者

wcf progressive download

开发者 https://www.devze.com 2023-02-27 01:12 出处:网络
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 play

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.


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.


See my answer to this question here Developing A Streaming Server For Android which basically describes simply using IIS as the server to 'open' (and progressively stream) mp3 files using AsyncPlayer on Android (the same works for MediaPlayer).

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

Just some alternative ideas to WCF.

0

精彩评论

暂无评论...
验证码 换一张
取 消