2

程序员,这个问题让我发疯了!!在过去的两天里,我一直在做广泛的研究,但我不知道发生了什么。

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

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

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

解决方案信息:

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

  • 使用 WCF 的 Silverlight 项目。

网页配置

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

提前致谢。

4

1 回答 1

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>
于 2011-01-18T05:58:41.473 回答