【问题标题】:WCF The maximum message size quota for incoming messages (65536) has been exceededWCF 已超出传入邮件 (65536) 的最大邮件大小配额
【发布时间】:2018-01-15 17:07:45
【问题描述】:

我希望你能帮助我,因为我一直在努力解决这个问题,我尝试了从本网站上的建议以及通过谷歌搜索解决同一问题的所有解决方案,但均无济于事。其中包括:

Wcf-The maximum message size quota for incoming messages (65536) has been exceeded?

WCF, The maximum message size quota for incoming messages (65536) has been exceeded

The maximum message size quota for incoming messages (65536) has been exceeded

Why do I still get "The maximum message size quota for incoming messages (65536) has been exceeded" error?

正如标题所示,我的传入消息的最大消息大小存在问题。我正在尝试覆盖默认消息大小,但无论我尝试什么它都不起作用,而且我收到的错误往往指向我在 App.config 文件中的自定义配置没有使用默认设置。

我正在使用 WCF 服务主机/WCF 测试客户端和 Visual Studio 2017 Professional,我的客户端项目是更广泛的 WPF MVVM 项目的类库。我还没有将 WCF 服务复制到测试 Server 2012/IIS 安装,因为这应该可以在我的开发环境中使用?

我正在尝试仅增加 AirplaneService 的最大消息大小,而将所有其他服务保留为默认设置。

我的客户端 App.Config 仅在我的类库客户端中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /></startup><system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IAirplaneService" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"  />
        </binding>
        <binding name="BasicHttpBinding_ILicenceService" />
        <binding name="BasicHttpBinding_ICustomerService" />
        <binding name="BasicHttpBinding_IMembershipService" />
        <binding name="BasicHttpBinding_IPrefixService" />
        <binding name="BasicHttpBinding_ICountryService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAirplaneService"
        contract="AirplaneService.IAirplaneService" name="BasicHttpBinding_IAirplaneService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/LicenceService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILicenceService"
        contract="LicenceService.ILicenceService" name="BasicHttpBinding_ILicenceService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CustomerService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomerService"
        contract="CustomerService.ICustomerService" name="BasicHttpBinding_ICustomerService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/MembershipService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMembershipService"
        contract="MembershipService.IMembershipService" name="BasicHttpBinding_IMembershipService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/PrefixService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPrefixService"
        contract="PrefixService.IPrefixService" name="BasicHttpBinding_IPrefixService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CountryService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICountryService"
        contract="CountryService.ICountryService" name="BasicHttpBinding_ICountryService" />
    </client>
  </system.serviceModel>
</configuration>

我相信我只需要修改客户端 App.Config,因为我不希望在服务端接收大消息。但是,为了完整起见,我还在我的 Service App.Config 中添加了相关绑定:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="FlightSchoolEntities" connectionString="metadata=res://*/FlightSchoolModel.csdl|res://*/FlightSchoolModel.ssdl|res://*/FlightSchoolModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xx.xx.xx.xx;initial catalog=FlightSchool;persist security info=True;user id=sa;password=xxxxxxxxxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Flight_School.Service.CountryService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CountryService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ICountryService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.PrefixService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/PrefixService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.IPrefixService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
      <service name="Flight_School.Service.MembershipService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/MembershipService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.IMembershipService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.CustomerService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CustomerService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ICustomerService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.LicenceService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/LicenceService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ILicenceService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.AirplaneService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBasicBinding" contract="Flight_School.Service.IAirplaneService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

运行这个我收到以下错误:

System.ServiceModel.CommunicationException: '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.'

发生错误的代码的sn-p:

            using (AirplaneService.AirplaneServiceClient service = new AirplaneService.AirplaneServiceClient())
            {
                List<AirplaneService.Manufacturer> manufacturers = service.GetManufacturers();

如果我将结果限制在 service->GetManufacturers() 中,它会按预期返回制造商列表。

每次我重新运行我的服务时,我都需要更改 WCF 测试客户端中的配置,但即使这样做了,我在运行项目时仍然收到相同的错误。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAirplaneService" sendTimeout="00:05:00"
                    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAirplaneService"
                contract="IAirplaneService" name="BasicHttpBinding_IAirplaneService" />
        </client>
    </system.serviceModel>
</configuration>

我们将非常感谢您的帮助,并在此先感谢您。

理查德。

【问题讨论】:

  • 我的客户端 App.Config 仅在我的类库客户端中您的配置必须在您正在执行的项目(Client.exe、Server.exe)中,而不是在图书馆。
  • 谢谢你,拉班,我在这部电影中担任主角肯定是断断续续地度过了一整天,而显而易见的事情并没有浮现在脑海中!我已将自定义绑定配置添加到我的 .exe 项目中的 App.config 文件中,它按预期工作。大约一周前,当我将初始服务绑定添加到同一个 App.config 文件时,我一定是脑筋急转弯。再次感谢。

标签: c# .net wcf


【解决方案1】:

将以下内容添加到您的绑定中。

 <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IAirplaneServicer" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647" />
     </binding>
  </basicHttpBinding>
</bindings>

【讨论】:

    【解决方案2】:

    感谢 Rabban,他指出我需要将自定义绑定添加到 .exe 项目 App.config 文件中,它现在可以按预期工作。大约一周前,我不得不手动将 WCF 服务绑定添加到 .exe 项目 App.config 文件中,从那时到现在我都忘记了那个。我还从服务项目 App.config 中删除了自定义绑定,因为这不是必需的,因为我不想向服务发送大量数据传输。再次感谢。

    【讨论】:

      猜你喜欢
      • 2015-09-15
      • 2015-06-13
      • 2012-03-13
      • 2014-02-13
      • 2011-02-23
      相关资源
      最近更新 更多