首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET托管WCF服务,需要增加MaxStringContentLength,但如何增加?

ASP.NET托管WCF服务,需要增加MaxStringContentLength,但如何增加?
EN

Stack Overflow用户
提问于 2013-02-11 23:53:42
回答 2查看 473关注 0票数 0

我的ASP.NET服务器提供了一组由我的WPF客户端使用的WCF服务。直到字符串字段的长度超过8K为止,一切都很正常。这将在ASP.NET服务器上生成以下异常.

反序列化Project.ModelType类型的对象时出错。读取XML数据时已超出最大字符串内容长度配额(8192)。可以通过更改在创建XML读取器时使用的MaxStringContentLength对象上的XmlDictionaryReaderQuotas属性来增加此配额。

我已经在WPF MaxStringContentLength上将app.config的值提高到64K,但这并没有解决这个问题。因此,我想我也需要在ASP.NET端增加这个值。但是我在web.config中没有任何要更改的值!这是我的web.config来展示这个..。

代码语言:javascript
复制
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms name=".ASPXFTOAUTH"
             timeout="10"
             slidingExpiration="true"
             cookieless="UseCookies"/>
    </authentication>

    <membership>
      <providers>
        <clear/>
      </providers>
    </membership>

    <customErrors defaultRedirect="~/Error.htm" mode="RemoteOnly">
      <error statusCode="404" redirect="~/404.aspx" />
    </customErrors>
  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                               multipleSiteBindingsEnabled="true" />
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

那么,如何更新服务器以指示较高的MaxStringContentLength值?我服务的app.config看起来是这样的..。

代码语言:javascript
复制
<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IAccess" closeTimeout="00:01:00"
               openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
               allowCookies="false" bypassProxyOnLocal="false"
               hostNameComparisonMode="StrongWildcard"
               maxBufferSize="131072" maxBufferPoolSize="524288" maxReceivedMessageSize="131072"
               messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
               useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="65536" 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 binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IAccess" 
              contract="AccessService.IAccess"
              name="BasicHttpBinding_IAccess" />
  </client>
</system.serviceModel>

有什么想法吗?

更新:

我的服务是通过拥有类'Access.svc‘来定义的

代码语言:javascript
复制
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Access : IAccess
{
    // ...IAccess method implementations
}

...which有以下标记..。

代码语言:javascript
复制
<%@ ServiceHost Language="C#" Debug="true" 
                Service="Ecotech.AMS.WebServer.Access" 
                CodeBehind="Access.svc.cs" %>

正如注释中所指出的,...there与web.config中的服务无关。

EN

回答 2

Stack Overflow用户

发布于 2013-02-12 01:38:24

尝试通过右键单击项目的菜单单击“添加服务引用”。这样做会将必要的配置信息添加到web.config文件中。

完成此操作后,可以在绑定上设置maxReceivedMessageSize属性。这样做将最准确地反映您在WCF服务方面所做的事情。

票数 0
EN

Stack Overflow用户

发布于 2013-02-12 03:58:58

您需要处理的地方是web配置,您需要添加可以设置数据大小的服务行为。举个例子,

代码语言:javascript
复制
<behaviors>
      <serviceBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>

      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="SilverlightWCFLargeDataApplication">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

如果这不起作用,那么发布您的web配置here.Hope就会有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14823164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档