I have a WCF service that accepts a stream:
[ServiceContract]
public class UploadService : BaseService
{
[OperationContract]
[WebInvoke(BodyStyle=WebMessageBodyStyle.Bare, Method=WebRequestMethods.Http.Post)]
public void Upload(Stream data)
{
}
}
This method allows my Silverlight application to download large binaries, the easiest way is to manually process the HTTP request from the client. Here is the code in the Silverlight client that does this:
const int contentLength = 64 * 1024;
var request = (HttpWebRequest)WebRequest.Create("http://localhost:8732/UploadService/");
request.AllowWriteStreamBuffering = false;
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/octet-stream";
request.ContentLength = contentLength;
using (var outputStream = request.GetRequestStream())
{
outputStream.Write(new byte[contentLength], 0, contentLength);
outputStream.Flush();
using (var response = request.GetResponse());
}
Now, in the above case, when I transfer 64 KB of data (or less), this one works fine , and if I set a breakpoint in my WCF method, and I can check the stream and see 64 KB zeros - yay!
The problem occurs if I send more than 64 KB of data , for example, changing the first line of my client code to the following:
const int contentLength = 64 * 1024 + 1;
, request.GetResponse():
: (400) .
WCF maxReceivedMessageSize, maxBufferSize maxBufferPoolSize 2147483647, . app.config:
<service name="UploadService">
<endpoint address=""
binding="webHttpBinding"
bindingName="StreamedRequestWebBinding"
contract="UploadService"
behaviorConfiguration="webBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/UploadService/" />
</baseAddresses>
</host>
</service>
<bindings>
<webHttpBinding>
<binding name="StreamedRequestWebBinding"
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
hostNameComparisonMode="WeakWildcard"
sendTimeout="00:05:00"
openTimeout="00:05:00"
receiveTimeout="00:05:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="StreamedRequest">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
<endpointBehaviors>
</behaviors>
64 ?
: , , HTTP . ( , Silverlight .)