2017-08-08 56 views
1

我希望你能幫助我,因爲我一直在撕掉我的頭髮與這個問題,試圖從這個建議對這個問題的所有解決方案網站,也通過谷歌無濟於事。其中許多人:WCF傳入郵件的最大郵件大小限額(65536)已被超出

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專業版,我的客戶端項目是更廣泛的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(); 

如果我在service-> GetManufacturers()中限制了我的結果,它將按照預期返回製造商列表。

每次我重新運行我的服務時,我需要更改WCF Test Client中的配置,但即使這樣做後,運行該項目時仍會收到相同的錯誤。

<?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> 

您的幫助將得到最多的讚賞和許多提前感謝。

Richard。

+0

_My客戶端App.Config,我在我的類庫客戶端only_您的配置必須在您執行的項目(Client.exe,Server.exe),而不是在庫中。 – Rabban

+0

謝謝拉班,我在這裏主演了這一整天必須的一切,並且顯而易見的並不令人想到!我已將自定義綁定配置添加到我的.exe項目中的App.config文件,並且它按預期工作。我一定是在大約一週前將我的初始服務綁定添加到相同的App.config文件中,從而導致大腦褪色。非常感謝。 –

回答

0

將以下內容添加到您的綁定中。

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

感謝拉班誰指出我需要添加我的自定義綁定到.exe項目app.config文件,現在按預期工作。我必須在一個星期左右之前手動將WCF服務綁定添加到.exe項目的App.config文件中,然後在那之間和現在我忘了所有關於那個的。我也從服務項目App中刪除了自定義綁定。因爲這不是必需的,因爲我不想發送大量數據傳輸到服務。非常感謝。

相關問題