2011-06-20 59 views
0

我有WCF服務庫與此配置:WCF串流播放errror(最大郵件大小配額)

<basicHttpBinding> 
    <binding name="httpLargeMessageStream" 
     maxReceivedMessageSize="2147483647"  
     messageEncoding="Mtom" transferMode="Streamed" /> 
</basicHttpBinding> 

<netTcpBinding> 
    <binding name="tcpLargeMessageStream" transferMode="Streamed" 
      maxReceivedMessageSize="2147483647" /> 
</netTcpBinding> 

,並從客戶端,如果我發送請求上傳文件,然後所有工作正常

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); 
    } 
} 

但對於下載請求我已經得到了錯誤:

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); 
    } 
} 

客戶端調用方法:

// 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); 
     } 
    } 
} 

回答

4

的maxReceievedMessageSize是數據有多大,接收器準備接受。在上面的代碼中,爲了下載,客戶端就是接收者。你需要增加maxReceievedMessageSize在客戶端,以及(你似乎沒有從您所顯示的代碼,這樣做)

+0

Blewett thx man!該死的錯。 –

0

使用此

MAXBUFFERSIZE =「2147483647」 maxReceivedMessageSize =「2147483647」

在發送端和接收端。

相關問題