【问题标题】:RestFul Wcf Video Streaming to iPhone ClientRestFul Wcf 视频流到 iPhone 客户端
【发布时间】:2012-08-20 14:53:17
【问题描述】:

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

这里是c#代码

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>

【问题讨论】:

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


    【解决方案1】:

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

    FileStream stream = new FileStream(video_path, FileMode.Open, FileAccess.Read);
    
                        WebOperationContext.Current.OutgoingResponse.ContentType = "video/quicktime";
                        return stream;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      相关资源
      最近更新 更多