現在、クライアントに大きな (数ギガバイト) mpeg ビデオ ファイルを提供できるように、WCF ベースのサーバーを修正しています。
クライアントは、ダウンロード中にビデオを保存して表示する必要があります。ビデオが完全にメモリにロードされたため、バッファリングされたサービスが失敗しました。
wget.exeやWebブラウザで取得しようとすると、一部(600~800MB程度)しか読み込まれず、クライアント側でもサーバー側でもエラーなく停止します。
Internet Explorer でビデオ ストリームを開くと、下部にタイム スライダーが表示されず、HTTP 応答のヘッダーに content-length がありません。
HTTP 応答のヘッダーには Content-Length が含まれていませんが、コードで設定されています (以下を参照)。
この問題を解決する方法、または別の方法を知っている人はいますか?
サービスのコントラクト インターフェイス:
[ServiceContract(Namespace = "http://www.blah.com/MyFunnyVideos")]
public interface IMyFunnyVideosService
{
[OperationContract(Name = "GetVideo")]
[WebGet(UriTemplate = "LORESVIDEO/{videoId}", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
Stream GetVideo(string videoId);
}
実装:
[ServiceBehavior(Namespace = "http://www.blah.com/MyFunnyVideos", InstanceContextMode = InstanceContextMode.PerCall)]
public class MyFunnyVideosService : IMyFunnyVideosService
{
// ...
Stream IMyFunnyVideosService.GetVideo(string videoIdString)
{
Logger.LogMethod();
try
{
FileStream fstream = GetVideoFileStream(int.Parse(videoIdString));
fstream.OpenRead();
var response = WebOperationContext.Current.OutgoingResponse;
response.ContentLength = fstream.Length;
return fstream;
// ...
}
Web サービス構成には以下が含まれます。
<webHttpBinding>
<binding name="restBinding" transferMode="StreamedResponse" maxBufferSize="21474836470" maxReceivedMessageSize="21474836470" />
</webHttpBinding>
<behaviors>
<endpointBehaviors>
<behavior name="[omitted]">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
HTTP 応答ヘッダー:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: video/mpeg
Server: Microsoft-HTTPAPI/2.0
Date: Thu, 30 Jan 2013 15:52:04 GMT