【问题标题】:I cannot change maximum size quota for incoming message, WCF Service我无法更改传入消息 WCF 服务的最大大小配额
【发布时间】:2018-08-31 09:54:23
【问题描述】:
**Web Config:**
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1" />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <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>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <!--Add refernce to any new service that is to be added
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="EmployeeService.svc" service="PeopleInbox.ServiceLibrary.EmployeeService" />
        <add relativeAddress="LookupService.svc" service="PeopleInbox.ServiceLibrary.LookupService" />
        <add relativeAddress="SecurityService.svc" service="PeopleInbox.ServiceLibrary.SecurityService" />
        <add relativeAddress="EmployerService.svc" service="PeopleInbox.ServiceLibrary.EmployerService" />
      </serviceActivations>
    </serviceHostingEnvironment>-->
    <services>
      <service name="PeopleInbox.ServiceLibrary.EmployeeService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IEmployeeService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/EmployeeService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.AdminService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.IAdminService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/AdminService/" />
          </baseAddresses>
        </host>
      </service>

      <service name="PeopleInbox.ServiceLibrary.LookupService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ILookupService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/LookupService/" />
          </baseAddresses>
        </host>
      </service>
      <service name="PeopleInbox.ServiceLibrary.SecurityService">
        <endpoint address="" binding="basicHttpBinding" contract="PeopleInbox.ServiceLibrary.ISecurityService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/PeopleInbox.ServiceLibrary/SecurityService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>
</configuration>

错误 已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

请告诉在哪里设置 maxReceivedMessageSize。我无法创建绑定,也不知道如何使用。我检查了很多教程,但找不到使代码运行的正确答案。谢谢

【问题讨论】:

    标签: wcf binding maxreceivedmessagesize


    【解决方案1】:

    您需要创建一个绑定配置并将其分配给服务的bindingConfiguration 属性。

    要创建绑定,请在配置文件的 &lt;system.serviceModel&gt; 部分中添加一个部分,例如:

    <bindings>
      <basicHttpBinding>
        <binding name="MyHttpBinding" 
                 maxReceivedMessageSize="2147483647" />
      </basicHttpBinding>
    </bindings>
    

    然后在您的服务端点中,通过&lt;endpoint&gt; 元素上的bindingConfiguration 属性分配上述绑定。例如:

    <endpoint address="" binding="basicHttpBinding" 
              bindingConfiguration="MyHttpBinding"
              contract="PeopleInbox.ServiceLibrary.IAdminService">
    

    这将导致定义的端点使用您定义的绑定(将 maxReceivedMessageSize 值设置为属性的最大值 (Int32.MaxValue),而不是 basicHttpBinding 的默认值 65536。

    【讨论】:

    • 请根据我的网络配置回答我。我已经做了所有这些策略,但无法最大化邮件大小配额。
    猜你喜欢
    • 1970-01-01
    • 2015-04-02
    • 2014-02-01
    • 2014-10-23
    • 2010-12-15
    • 2013-11-03
    • 2020-10-06
    • 2014-06-24
    • 1970-01-01
    相关资源
    最近更新 更多