【发布时间】:2010-06-28 19:18:22
【问题描述】:
我不知所措...不知道为什么会发生这种情况。我在 Google 中浏览了至少 50 页,并在 StackOverflow 上搜索了这个答案。当我运行此代码时,我不断收到错误消息:
“尝试反序列化参数http://tempuri.org/:message 时出错。InnerException 消息是“反序列化Application.Interfaces.Mail.MailMessage 类型的对象时出错。最大字符串内容长度配额(8192)有读取 XML 数据时已超出。可以通过更改创建 XML 读取器时使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性来增加此配额。'"
这是我在 WCF 服务(服务器)上的内容:
<system.serviceModel>
<services>
<service behaviorConfiguration="SimpleServiceBehavior" name="Application.Services.Mail.Mailer">
<host>
<baseAddresses>
<add baseAddress="http://myapp.com/"/>
</baseAddresses>
</host>
<endpoint bindingConfiguration="BasicHttpBinding_IMailer" bindingName="BasicHttpBinding_IMailer" binding="basicHttpBinding" address="http://myapp.com/" contract="Application.Services.Local.Mail.IEmailer">
<identity>
<dns value="myapp.com"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SimpleServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMailer" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="800000" maxBufferPoolSize="800000" maxReceivedMessageSize="800000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="800000" maxStringContentLength="800000" maxArrayLength="800000" maxBytesPerRead="800000" maxNameTableCharCount="800000" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
我在客户端拥有什么:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMailer" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="5242880" maxBufferPoolSize="524288" maxReceivedMessageSize="5242880" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" 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://myapp.com/Mail/Mailer.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMailer" contract="Interfaces.Mail.IEmailer" name="BasicHttpBinding_IMailer"/>
</client>
</system.serviceModel>
【问题讨论】:
-
您是否尝试在代码中(而不是在 app.config 文件中)设置绑定?我有一个 NetTcpBinding 的工作设置,但我看到你想使用 BasicHttpBinding,所以我不想在这里粘贴它。
-
不,我没有使用代码尝试过。如果我在代码和配置中绑定它有什么区别?
-
理论上,没什么。然而,我确实不得不努力让 net.tcp 工作,并且有一种情况我不得不在客户端求助于基于代码的解决方案(请参阅geekswithblogs.net/RandyMichak/archive/2009/03/04/…)
-
你回答应该回答问题;这没有帮助。 -1.