WCF Streamed errror (maximum message size quota)
I have WCF service library with this config:
<basicHttpBinding>
<binding name="httpLargeMessageStream"
maxReceivedMessageSize="2147483647"
messageEncoding="Mtom" transferMode="Streamed" />
</basicHttpBinding>
<netTcpBinding>
<binding name="tcpLargeMessageStream" transferMode="Streamed"
maxReceivedMessageSize="2147483647" />
</netTcpBinding>
and from client side if I send request for upload file, then all work fine
public void UploadFile(FileUploadMessage request)
{
try
{
// Gets absolute local storing path
string localPath = Path.Combine(basePath, request.UploadMetadata.StoringPath);
// Create folders in they don't exist
FileInfo file = new System.IO.FileInfo(localPath);
file.Directory.Create();
// Get document path on server
string serverFileName = Path.Combine(localPath, request.UploadMetadata.HashFileName);
// Create a new temp document
using (FileStream outfile = new FileStream(serverFileName, FileMode.Create))
{
// Read buffer
const int bufferSize = 65536;
// Output buffer
Byte[] buffer = new Byte[bufferSize];
int bytesRead;
// Write bytes from source into local file
while ((bytesRead = request.FileByteStream.Read(buffer, 0, bufferSize)) > 0)
{
outfile.Write(buffer, 0, bytesRead);
}
}
}
catch (IOException e)
{
throw new FaultException<IOException>(e);
}
}
but for download request I already got error:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
public FileDownloadReturnMessage DownloadFile(FileDownloadMessage request)
{
try
{
controlServerAdress = "http://localhost:8080/ControlServer/";
EndpointAddress basicBinding = new EndpointAddress(controlServerAdress + "TokenService/basic");
tokenService = new TokenServiceClient("BasicHttpBinding_ITokenService", basicBinding);
// Get file token form control server
ComDocFile file = tokenService.ResolveToken(request.DownloadMetadata.Token);
// If exist file for token
if (file != null)
{
// 开发者_运维知识库Get document path on server
string serverFileName = Path.Combine(basePath, file.FilePath, file.FileName);
// Set fileName
request.DownloadMetadata.FileName = file.FileName;
// Return file stream
return new FileDownloadReturnMessage(new FileStream(serverFileName, FileMode.Open, FileAccess.Read), new ReturnDownloadMetaData(file.FileName, true));
}
return new FileDownloadReturnMessage(null,
new ReturnDownloadMetaData(null, false));
}
catch (IOException e)
{
throw new FaultException<IOException>(e);
}
}
Client calling method:
// Read buffer
const int bufferSize = 65536;
// Output buffer
Byte[] buffer = new Byte[bufferSize];
int bytesRead;
// Prepare download stream
Stream donwloadStream;
ReturnDownloadMetaData file = fileClient.DownloadFile(downloadMetaData, out donwloadStream);
// If file server return valid file stream
if (file.IsValid)
{
// Create a new temp document
using (FileStream outfile = new FileStream("C:\\#ComDocs_FileServer\\" + file.FileName, FileMode.Create))
{
// Write bytes from source into local file
while ((bytesRead = donwloadStream.Read(buffer, 0, bufferSize)) > 0)
{
outfile.Write(buffer, 0, bytesRead);
}
}
}
the maxReceievedMessageSize is how big the data is that the receiver is prepared to accept. In the code above, for download, the client is the receiver. You need to increase the maxReceievedMessageSize in the client as well (you don't appear to be doing this from the code you have shown)
Use this
maxBufferSize ="2147483647" maxReceivedMessageSize="2147483647"
at both sender and receiver end.
精彩评论