【问题标题】:Configuration of a Wcf Service: Web.config maxReceivedMessageSize not working (Even with edit wcf Configuration)Wcf 服务的配置:Web.config maxReceivedMessageSize 不起作用(即使使用编辑 wcf 配置)
【发布时间】:2015-09-12 11:39:58
【问题描述】:

为了轻松重现错误,我创建了一个名为 TestService 的新 wcf 服务。

当我执行 9999 次循环时,我收到了所需的消息:已超出传入消息的最大消息大小配额 (65536)。

所以我更改了其他 stackoverflow 踏板上描述的必需内容。但没有成功...然后我使用工具 Wcf Service Configurator 找到了本手册 (http://keithelder.net/2008/01/17/exposing-a-wcf-service-with-multiple-bindings-and-endpoints/)。但同样的错误。

这里是配置:

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttp" maxBufferPoolSize="9999999" maxBufferSize="9999999"
      maxReceivedMessageSize="9999999" />
  </basicHttpBinding>
</bindings>
<services>
  <service name="TestService.Service1">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttp"
      name="BasicHttp" contract="TestService.IService1" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

如果你想要代码。我很高兴分享它。不过,这只是一个填充字符串列表的循环。

编辑:我添加了一个新服务,所以我可以有一个客户端配置。问题依然存在。

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
  <service name="TestService2.Service1">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttp"
      name="BasicHttp" contract="TestService2.IService1"  />
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttp" maxBufferSize="65536999" maxReceivedMessageSize="65536999">
      <readerQuotas maxStringContentLength="65536999" maxArrayLength="65536999" />
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:58526/Service1.svc" binding="basicHttpBinding"
    bindingConfiguration="BasicHttp" contract="ServiceReference1.IService1"
    name="BasicHttp" />
</client>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>  
</configuration>

【问题讨论】:

    标签: c# web-services wcf web-config wcf-binding


    【解决方案1】:

    您必须确保客户端和服务器配置文件都具有适当的值,如下所示: 服务器端(无名绑定):

    <basicHttpBinding>
            <binding 
                     maxReceivedMessageSize="20000000" 
                     maxBufferSize="20000000"
                     maxBufferPoolSize="20000000">
                <readerQuotas maxDepth="1024" 
                     maxArrayLength="200000000"
                     maxStringContentLength="200000000"/>
            </binding>
        </basicHttpBinding>
    

    这也是行为:

    <behaviors>
      <serviceBehaviors>
        <behavior name="ECMSServiceBehavior">
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647" />
    </behavior>
      </serviceBehaviors>
    </behaviors>
    

    对于客户端:

    <basicHttpBinding>
            <binding 
                     maxReceivedMessageSize="20000000" 
                     maxBufferSize="20000000"
                     maxBufferPoolSize="20000000">
                <readerQuotas maxDepth="1024" 
                     maxArrayLength="200000000"
                     maxStringContentLength="200000000"/>
            </binding>
        </basicHttpBinding>
    

    希望对你有帮助。

    【讨论】:

    • 你不需要,问题出在配置文件中。你说你在运行一个测试,它是VS中的一个测试项目吗?您的 TestService 在其配置文件中有正确的值吗?
    • 是的。据我所知。你你别人只是做一个测试服务?又花了 8 个小时解决这个问题,但没有解决方案。配置文件; pastebin.com/nyhqUqVV
    【解决方案2】:

    客户端配置中存在问题。检查客户端配置。服务器端配置似乎没问题。

    【讨论】:

    • 我需要如何设置客户端配置?不在配置文件中?
    • 你怎么称呼这个服务??
    • 我没有打电话。只需使用所选服务对其进行分层,然后按播放键,然后加载 wcf 测试客户端。
    • 您可以使用 svcconfigeditor 更改默认端点配置。参考链接social.msdn.microsoft.com/Forums/vstudio/en-US/…
    • 如果我将服务添加到新服务中,我可以在 wcf 配置中增加它,然后它就可以工作了。但是当我部署错误返回!
    猜你喜欢
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2019-07-28
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多