2013-04-30 43 views
0

嗯,我已經找了幾個小時的問題的答案,但我不能擺脫。我正在使用WCF Web服務從服務器下載文件。爲了測試,我使用了3種不同的文檔(PDF),其中1個大小爲24Kb,另外2個大小爲60KB。我可以下載第一(24KB),但沒有其他人可以下載,每次我嘗試時,Visual Studio顯示此異常:不能超過WCF的最大接收郵件錯誤

傳入郵件的最大郵件大小限額(65536)已超過

我讀過緩衝區的默認大小爲64KB,所以我不知道爲什麼我無法下載60KB大小的文件。我試圖改變我的配置(服務器和客戶端)的緩衝區大小,甚至嘗試使用流傳輸和它的相同的事情。

這裏是我的config文件的代碼(在服務器上):

<system.serviceModel> 

<services>  
    <service behaviorConfiguration="MyServiceTypeBehaviors" name="CAVTransactions"> 
    <endpoint address="CAV" binding="basicHttpBinding" bindingConfiguration="bindingIntegrator" 
     name="CAV" contract="ICAVContract" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://XX.XXX.X.XX:XXXX/App_Code/" /> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

<bindings> 
    <basicHttpBinding> 
    <binding name="bindingIntegrator" 
      maxReceivedMessageSize="2147483647" 
      maxBufferSize="2147483647" transferMode="Streamed" > 

     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647"/> 
    </binding> 
    </basicHttpBinding> 
</bindings> 

<behaviors> 

    <serviceBehaviors> 

    <behavior name="MyServiceTypeBehaviors"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="6553600"/> 
    </behavior> 

    </serviceBehaviors> 
</behaviors>  

我的config文件的代碼(客戶端):

<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="bindingIntegrator" 
      maxReceivedMessageSize="2147483647" 
      maxBufferSize="2147483647" transferMode="Streamed" > 

      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
       maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
       maxNameTableCharCount="2147483647"/> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost/IntegratorWCFService/CAVTransactions.svc/CAV" 
      binding="basicHttpBinding" bindingConfiguration="bindingIntegrator" contract="CAVService.ICAVContract" 
      name="CAV" /> 
    </client> 
</system.serviceModel> 

我的合同:

[OperationContract] 
Stream DownloadFileOther(string documentName); 

public Stream DownloadFileOther(string documentName) 
{ 

    System.IO.Stream str; 
    try 
    { 
     //string filePath = System.IO.Path.Combine(@"C:\CAV_Documents", request.FileName); 
     string filePath = System.IO.Path.Combine(@"C:\CAV_Documents", documentName + ".pdf"); 
     FileInfo fileInfo = new FileInfo(filePath); 

     //Chequeo de existencia 
     if (!fileInfo.Exists) 
     { 
      throw new FileNotFoundException("Archivo no encontrado", documentName); 
     } 

     //Apertura de stream 
     FileStream stram = new FileStream(filePath, FileMode.Open, FileAccess.Read); 

     str = stram; 

     //resultado 
     //result.FileName = request.FileName; 
     //result.Length = fileInfo.Length; 
     //result.FileByteStream = stram; 

    } 
    catch (Exception e) 
    { 
     Console.WriteLine(e.Message); 
     throw new NotSupportedException(); 
    } 

    return str; 
    //return 0; 
} 

而代碼爲dow nload文件:

try 
       { 
        Stream stream; 

        string codigo = selectedRevision.Code.ToString(); 

        stream = ClientManager.CreateCAVServiceClient().DownloadFileOther(codigo); 

        string key = Guid.NewGuid().ToString(); 


        using (var file = File.Create("Temp\\" + key + ".pdf")) 
        { 
         stream.CopyTo(file); 
        } 

        string GuidePath = @"./Temp/" + key + ".pdf"; 
        string fullPath = System.IO.Path.GetFullPath(GuidePath); 
        Uri GuideURI = new Uri(fullPath, UriKind.Absolute); 

        selectedRevision.DocumentPath = GuideURI; 

       } 
       catch (Exception ex) 
       { 
        Console.WriteLine(ex.Message); 
       } 

我很感激,如果你們中的一些人可以給我一些意見來幫助我。謝謝!

+0

錯誤消息似乎在抱怨HTTP請求的大小,而不是響應的大小。如果後臺傳輸是HTTP,也許嘗試使用Fiddler觀看? – EricLaw 2013-04-30 22:55:56

+1

'ClientManager.CreateCAVServiceClient()。DownloadFileOther(codigo)' - 這是指創建指定客戶端的自定義類,還是「ClientManager」是您的服務引用,「CreateCAVServiceClient」是提供的構造函數?我在想,如果'ClientManager'是某種自定義實現,你可能會遇到默認綁定/端點的問題。你可以顯示'ClientManager.CreateCAVServiceClient'的代碼嗎? – Tim 2013-05-01 01:35:49

+0

ClientManager是我創建的類,CreateCAVServiceClient是創建CAVServiceClient的靜態方法。我要編輯帖子並顯示代碼。 Thx – 2013-05-01 17:03:25

回答

0

在您的服務器配置更改此

<serviceBehaviors> 

<behavior name="MyServiceTypeBehaviors"> 
    <serviceMetadata httpGetEnabled="true" /> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
</behavior> 

0

畢竟,這是一件添我的問題發表了評論。我正在使用自定義類來創建我的綁定(ClientManager.CreateCAVServiceClient)我沒有更改該類中的綁定,因此緩衝區大小沒有被修改。感謝Tim解決我的問題,以及其他人給我建議:D!

相關問題