RestFul Wcf视频流到iPhone客户端

时间:2012-08-20 14:53:18

标签: c# wcf windows-services windows-server-2008 wcf-data-services

您好我正在尝试在移动客户端上播放来自我宁静的wcf服务的视频。当我打开链接时,它不会在mediaPlayer和浏览器中播放视频,实际上开始下载文件。

这是c#Code

public Stream playVideo(string VideoId)
        {
            HttpContext context = HttpContext.Current;
            if (response[1] != null)
            {
                string video_path = Constants._VideosDirectory + "\\" + response[1] + "\\" + VideoId + ".MOV";
                if (File.Exists(video_path))
                {
                    FileStream stream = new FileStream(video_path, FileMode.Open, FileAccess.Read);

                    FileInfo fileInfo = new FileInfo(video_path);
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.FullName.Replace(" ", "_"));
                    context.Response.ContentType = ReturnFiletype(fileInfo.Extension.ToLower());
                    WebOperationContext.Current.OutgoingResponse.ContentType = "video/quicktime";
                    return stream;
                }
}
}

这是此服务的webhttpBinding

<bindings>

     <webHttpBinding>
   <binding transferMode="Streamed"
            maxBufferPoolSize="250000000"
            maxBufferSize="5242880"
            maxReceivedMessageSize="2147483647"
            openTimeout="05:25:00"
            closeTimeout="00:25:00"
            sendTimeout="00:25:00"
            receiveTimeout="0:25:00"
            name="webBinding"
       /></webHttpBinding>
   </bindings>
 <service behaviorConfiguration="RestBehavior" name="Test.StreamVideo">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="webBinding"
           contract="Test.IStreamVideo" />
      </service>

1 个答案:

答案 0 :(得分:1)

更改代码解决了我的问题:)

FileStream stream = new FileStream(video_path, FileMode.Open, FileAccess.Read);

                    WebOperationContext.Current.OutgoingResponse.ContentType = "video/quicktime";
                    return stream;