WCF已超出传入邮件的最大邮件大小限额(65536)

时间:2017-08-08 08:23:49

标签: c# .net wcf

我希望你可以帮助我,因为我一直在用这个问题撕掉我的头发,从本网站的建议尝试了所有解决方案同样的问题,也通过谷歌无济于事。在许多其他人中:

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服务复制到测试服务器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,因为我不希望在服务端收到大量消息。但是,为了完整性,我还在服务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.'

发生错误的代码片段:

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

如果我限制我的服务结果 - > 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>

我们非常感谢您的帮助,并提前多多感谢。

理查德。

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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

相关问题