Reputation: 1324
I am currently fixing a WCF based server enabled to provide large (multiple gigabytes) mpeg video files for a client.
The client shall both save the video and view it while still downloading. A buffered service failed because the video was loaded into memory completely.
When I try to get it with wget.exe or a web browser, it loads only a part (roughly 600 to 800 MB), then it stops without an error, neither on the client nor on the server side.
When opening the video stream in Internet Explorer, no time slider appears on the bottom, and the HTTP response has no content-length in header.
The HTTP response contains no Content-Length in headers, although it has been set in the code (see below).
Does anybody know how to fix this problem, or an alternate way?
Contract interface of the service:
[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);
}
Implementation:
[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 service config contains:
<webHttpBinding>
<binding name="restBinding" transferMode="StreamedResponse" maxBufferSize="21474836470" maxReceivedMessageSize="21474836470" />
</webHttpBinding>
<behaviors>
<endpointBehaviors>
<behavior name="[omitted]">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
HTTP response headers:
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
Upvotes: 1
Views: 1017
Reputation: 1324
Got to answer my own question:
It was simply a timeout. Default sendTimeout in webHttpBinding is 1 minute, then the transmission stops without any error.
So, I only had to set sendTimeout="00:10:00" in the webHttpBinding, for a 10min timeout.
Upvotes: 2