简体   繁体   English

无法克服WCF的“最大已接收邮件数”错误

[英]Cant get over WCF's Max Received Messages error

Well, I've looking for an answer to my problem for several hours but I just cant get rid of. 好吧,我已经在寻找解决问题的方法了好几个小时,但我还是无法摆脱。 I'm using a WCF Web service to download a file from a server. 我正在使用WCF Web服务从服务器下载文件。 To test, I've used 3 different documents (PDF) 1 of them with a size of 24Kb and the other 2 with 60KB. 为了进行测试,我使用了3个不同的文档(PDF),其中1个文件的大小为24Kb,另2个文件的大小为60KB。 I can download the first (24KB) but none of the others can be downloaded, everytime I try , Visual Studio shows this exception: 我可以下载第一个文件(24KB),但是每次下载都不能下载其他文件,Visual Studio会显示此异常:

The maximum message size quota for incoming messages (65536) has been exceeded 超出了传入邮件的最大邮件大小配额(65536)

I've read that the default size of the buffer is 64KB, so I dont know why I can't download files with 60KB size. 我已经知道缓冲区的默认大小是64KB,所以我不知道为什么我不能下载60KB的文件。 I've tried to change the buffer size in my config (server and client) and even try with streaming transfer and its the same thing. 我试图更改配置(服务器和客户端)中的缓冲区大小,甚至尝试使用流传输及其相同的功能。

Here is my .config file code (on server): 这是我的.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>    

My .config file code (on client): 我的.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>

My Contract: 我的合同:

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

And the code for download the file: 以及下载文件的代码:

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

I'd appreciate if some of you guys could give me some comments to help me. 如果你们中的一些人能给我一些帮助的意见,我将不胜感激。 Thanks! 谢谢!

Did you check your client configuration file? 您检查客户端配置文件了吗? Even if you modified the service configuration file, client configuration always generate with the default settings. 即使您修改了服务配置文件,客户端配置也始终使用默认设置生成。 Please see my following blog post which has detailed how to tackle this error. 请参阅我的以下博客文章,其中详细介绍了如何解决此错误。

\\ http://thetechnocrate.wordpress.com/2012/05/24/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded/ \\ http://thetechnocrate.wordpress.com/2012/05/24/the-maximum-message-size-quota-for-incoming-messages-65536-has-been-exceeded/

in your server config change this 在您的服务器配置中更改此

<serviceBehaviors>

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

After all, it was something Tim commented in my question. 毕竟,这是蒂姆在我的问题中发表的评论。 I was using a custom class to create my binding (the ClientManager.CreateCAVServiceClient) I wasn't changing the binding in that class so the buffer size hadn't being modified.Thanks to Tim for solve my problem, and everyone else for giving me advices :D! 我正在使用自定义类创建绑定(ClientManager.CreateCAVServiceClient)我没有在该类中更改绑定,因此缓冲区大小没有被修改。感谢Tim解决了我的问题,以及其他所有人给我的帮助忠告:D!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM