WCF MaxStringContentLength永远不会更新!

时间:2011-01-18 05:50:38

标签: silverlight wcf maxstringcontentlength

编码员,这个问题让我抓狂!我在过去的两天里一直在进行广泛的研究,我不知道发生了什么。

问题:正如标题所说,我有一个由Silverlight应用程序使用的WCF服务。问题是每当我尝试使用其中一个WCF操作时,我都会收到此错误:

读取XML数据时已超出最大字符串内容长度配额(8192)。

我知道我应该将web.config中MaxStringContentLength的值更改为适合我的消息大小的值,但在我看来,更新MaxStringContentLength的值不会反映在系统中。我试图更新服务参考,重建整个解决方案没有运气,仍然得到相同的错误。知道我应该做什么吗?

解决方案信息:

  • 带有WCF文件夹的Asp.net项目。

  • 消耗的Silverlight项目 WCF。

的Web.config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding 
      name="BasicHttpBinding_Service1" 
      closeTimeout="00:01:00"
      openTimeout="00:01:00" 
      receiveTimeout="00:10:00" 
      sendTimeout="00:01:00"
      allowCookies="false" 
      bypassProxyOnLocal="false" 
      hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" 
      maxBufferPoolSize="524288" 
      maxReceivedMessageSize="65536"
      messageEncoding="Text" 
      textEncoding="utf-8" 
      transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas 
        maxDepth="32" 
        maxStringContentLength="10000" 
        maxArrayLength="16384"
        maxBytesPerRead="4096" 
        maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint 
    address="http://localhost:53931/WCF/Service1.svc" 
    binding="basicHttpBinding"
    bindingConfiguration="BasicHttpBinding_Service1"
    contract="ServiceReference.Service1"
    name="BasicHttpBinding_Service1" />
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

ServiceReferences.ClientConfig

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding 
              name="BasicHttpBinding_Service1" 
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647"

              >
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint 
          address="http://localhost:53931/WCF/Service1.svc" 
          binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_Service1"

          contract="ServiceReference.Service1"
          name="BasicHttpBinding_Service1" />
    </client>
</system.serviceModel>

提前致谢。

1 个答案:

答案 0 :(得分:2)

我没有看到web.config文件中任何地方定义的服务 - 你只需要一个服务客户端定义。我很惊讶这项服务甚至是这样的。可能会复制并粘贴错误?

这是我的web.config,用于类似的场景(你缺少标记的部分):

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <behaviors>
        <serviceBehaviors>
            <behavior name="MyDefaultBehavior">
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <bindings>
        <basicHttpBinding>
            <binding name="MyDefaultBinding" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000">
                <readerQuotas maxDepth="500" maxArrayLength="20000000" maxStringContentLength="20000000"/>
            </binding>
        </basicHttpBinding>
    </bindings>
    <services> <!-- This appears missing from your web.config -->
        <service behaviorConfiguration="MyDefaultBehavior" name="MyProject.MyService">
            <endpoint address="" binding="basicHttpBinding" contract="MyProject.IMyService" bindingConfiguration="MyDefaultBinding" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>