配置Wcf服务:Web.config maxReceivedMessageSize无法正常工作(即使使用编辑wcf配置)

时间:2015-09-12 11:39:58

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

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

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

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

这是Config:

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

2 个答案:

答案 0 :(得分:0)

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

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

希望它有所帮助。

答案 1 :(得分:-1)

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