【问题标题】:WCF MaxStringContentLength is never updated!WCF MaxStringContentLength 永远不会更新!
【发布时间】:2011-01-18 13:58:41
【问题描述】:

程序员,这个问题快把我逼疯了!!过去 2 天我一直在进行广泛的研究,但我不知道发生了什么。

问题:正如标题所说,我有一个被 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>

提前致谢。

【问题讨论】:

    标签: silverlight wcf maxstringcontentlength


    【解决方案1】:

    我没有在 web.config 文件的任何地方看到定义的服务 - 你只是在其中有一个服务 client 定义。我很惊讶这项服务甚至可以这样工作。可能是复制粘贴错误?

    这是我的类似场景的 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>
    

    【讨论】:

    • 根据msdn.microsoft.com/en-us/library/ms733932.aspx,“从 .NET Framework 4 中的简化配置模型开始,这个 [services] 部分是可选的。”无论如何,我想我必须添加这个 标记并进行相应的配置。
    • @ealshabaan:可选,除非您想进行更改。您的 Web 配置配置了客户端部分,但您需要配置服务部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    相关资源
    最近更新 更多