2013-02-11 32 views
0

我的ASP.NET服务器提供了一组由我的WPF客户端使用的WCF服务。一切都很好,直到字符串字段的长度超过8K。这现在在ASP.NET服务器上产生以下异常...ASP.NET托管WCF服务,需要增加MaxStringContentLength,但如何?

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

我已在MaxStringContentLength的增加值要对WPF的app.config 64K但这并没有解决这个问题。所以我想我需要在ASP.NET端增加这个值。但是我没有web.config中的任何值来更改!这里是我的web.config显示此...

<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看起来像这样...

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

任何想法?

UPDATE:

我的服务是由具有类的Access.svc“

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class Access : IAccess 
{ 
    // ...IAccess method implementations 
} 

...它具有以下标记定义...

<%@ ServiceHost Language="C#" Debug="true" 
       Service="Ecotech.AMS.WebServer.Access" 
       CodeBehind="Access.svc.cs" %> 

正如在评论中指出的那样,web.config中没有任何关于该服务的具体内容。

+0

你必须失去了一些东西。该_can't_不是你的整个web.config文件。你没有提及那里的服务。你是如何添加ServiceReference的? – 2013-02-11 23:59:05

+0

不确定,所以我不会将其作为答案发布,但唯一值在8K限制之下的是'maxBytesPerRead'。 MSDN指出“一个正整数,它指定每次读取返回的最大允许字节数。默认值是4096.'尝试增加此值 – Steve 2013-02-12 00:00:45

+0

@Steve,他需要在客户端设置这个值作为很好,但配置文件甚至没有对服务的引用。 – 2013-02-12 00:04:11

回答

0

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

一旦你做到这一点,你可以在你的绑定设置maxReceivedMessageSize属性。这样做会最准确地反映你在WCF服务方面所做的事情。

+0

右键点击我的WPF项目给出了“添加服务引用”选项,但右键单击ASP.NET项目没有。请注意,ASP.NET是托管服务的地方,所以我不认为将自己的服务引用添加到工作中。 – 2013-02-12 02:12:04

0

,你需要工作的地方是web配置,你需要添加的服务行为,您可以设置数据的大小。例如像这样,

<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它帮助。