【问题标题】:WCF Still get error with maximum message size when already increased itWCF 在已经增加最大消息大小时仍然会出现错误
【发布时间】:2017-05-14 09:39:19
【问题描述】:

我刚刚研究了很多主题,但不知道为什么,我仍然遇到这个问题。 我在服务器上的配置。

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyService.Services.Service">
        <endpoint  behaviorConfiguration="LargeDataBehavior" address="" binding="wsHttpBinding" contract="MyService.Services.UI.IService" bindingConfiguration="MyBinding">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/MyService.Services/Service/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding bypassProxyOnLocal="True" name="MyBinding" textEncoding="utf-8" 
                 maxReceivedMessageSize="2147483647"  maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" 
                  maxStringContentLength="2147483647" 
                  maxArrayLength="2147483647" 
                  maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
            <message clientCredentialType="UserName" algorithmSuite="Default"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="LargeDataBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483646" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="True"/>
          <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

然后我运行 WCF 测试客户端。

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

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

对不起,我的英语不好。 非常感谢您的帮助!

【问题讨论】:

    标签: .net web-services wcf


    【解决方案1】:

    服务的配置似乎不正确,因为在端点级别应用绑定配置后,最大大小仍然存在相同的问题。 您的绑定配置是正确的,但行为配置应该在服务级别而不是端点级别。

    behaviorConfiguration="newBehaviour"行为添加到服务级别节点,即'&lt;services&gt;'标签,您可以删除端点标签处的行为,因为行为是服务级别,因此请在服务标签上指定您的行为配置。

     <system.serviceModel>
        <services name="MyService.Services.Service" behaviorConfiguration="newBehaviour" >
        <endpoint  address=""   binding="wsHttpBinding" contract="MyService.Services.UI.IService" bindingConfiguration="MyBinding">
                 <identity>
                   <dns value="localhost" />
                </identity>
             </endpoint><endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
             <host>
                <baseAddresses>
                   <add baseAddress="http://localhost:8733/MyService.Services/Service/" />
                </baseAddresses>
             </host>
          </service>
       </services>
       <bindings>
          <wsHttpBinding>
             <binding bypassProxyOnLocal="True" name="MyBinding" textEncoding="utf-8" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                <security mode="None">
                   <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                   <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
             </binding>
          </wsHttpBinding>
       </bindings>
       <behaviors>
          <endpointBehaviors>
             <behavior name="LargeDataBehavior">
                <dataContractSerializer maxItemsInObjectGraph="2147483646" />
             </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
             <behavior name="newBehaviour">
                <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
                <serviceDebug includeExceptionDetailInFaults="True" />
                <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
             </behavior>
          </serviceBehaviors>
       </behaviors>
    </system.serviceModel>
    

    【讨论】:

    • 这不是我的问题。我做到了,仍然是同样的错误。感谢您的建议。
    • 很好,您似乎在使用 WCF 服务的客户端应用程序中添加了最大大小设置,我认为您也必须将这些设置添加到您的 WCF 服务中。
    【解决方案2】:

    根据错误,听起来您需要在 WCFTestClient 配置中增加maxReceivedMessageSize 属性,而不是服务。

    为此,请转到 WCFTestClient 左侧的底部并右键单击“配置文件”节点,然后选择“使用 SvcConfigEditor 编辑”。

    在弹出的窗口中,选择您要编辑的绑定,您可以在右侧窗格中根据需要调整所有值。

    请注意,这只会在该 WCFTestClient 会话中持续存在;关闭它后,您将丢失设置并恢复为默认值。

    【讨论】:

      猜你喜欢
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2010-09-27
      • 2013-11-03
      • 1970-01-01
      • 2015-04-02
      • 2020-10-06
      相关资源
      最近更新 更多