我的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来展示这个..。
<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>有什么想法吗?
更新:
我的服务是通过拥有类'Access.svc‘来定义的
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Access : IAccess
{
// ...IAccess method implementations
}...which有以下标记..。
<%@ ServiceHost Language="C#" Debug="true"
Service="Ecotech.AMS.WebServer.Access"
CodeBehind="Access.svc.cs" %>正如注释中所指出的,...there与web.config中的服务无关。
发布于 2013-02-12 01:38:24
尝试通过右键单击项目的菜单单击“添加服务引用”。这样做会将必要的配置信息添加到web.config文件中。
完成此操作后,可以在绑定上设置maxReceivedMessageSize属性。这样做将最准确地反映您在WCF服务方面所做的事情。
发布于 2013-02-12 03:58:58
您需要处理的地方是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就会有所帮助。
https://stackoverflow.com/questions/14823164
复制相似问题