WCF字符串过长问题解决方法指南

WCF框架是一个比较常用的开发框架,可以帮助开发人员实现许多功能,提供了相当大的帮助。编写基于WCF服务的程序时,向WCF服务端发送一长串的HTML源码,结果客户端收到提示如下:#t#

格式化程序尝试对消息反序列化时引发异常: 对操作“AddArticle”的请求消息正文进行反序列化时出现错误。读取 XML 数据时,超出***字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。 第 64 行,位置为 79。

WCF字符串过长问题主要是maxStringContentLength和maxReceivedMessageSize的设置会影响到消息的发送和接收,于是全部改为2MB大小,即2097152。

客户端app.config修改以解决WCF字符串过长问题:

  1. < bindings> 
  2. < basicHttpBinding> 
  3. < binding name="BasicHttpBinding_ShareService" 
    closeTimeout="00:01:00" 
  4. openTimeout="00:01:00" receiveTimeout="
    00:10:00" sendTimeout="00:01:00" 
  5. allowCookies="false" bypassProxyOnLocal=
    "false" hostNameComparisonMode="StrongWildcard" 
  6. maxBufferSize="65536" maxBufferPoolSize=
    "524288" maxReceivedMessageSize="2097152" 
  7. messageEncoding="Text" textEncoding=
    "utf-8" transferMode="Buffered" 
  8. useDefaultWebProxy="true"> 
  9. < !-- Reset maxStringContentLength 
    for deserialize --> 
  10. < readerQuotas maxDepth="32" 
    maxStringContentLength="2097152"
     maxArrayLength="16384" 
  11. maxBytesPerRead="4096" maxName
    TableCharCount="16384" /> 
  12. < security mode="None"> 
  13. < transport clientCredentialType="None" 
    proxyCredentialType="None" 
  14. realm="" /> 
  15. < message clientCredentialType="UserName" 
    algorithmSuite="Default" /> 
  16. < /security> 
  17. < /binding> 
  18. < /basicHttpBinding> 
  19. < /bindings> 

服务端web.config修改解决WCF字符串过长问题:

 
 
 
  1. < system.serviceModel> 
  2. < !-- add for the message size --> 
  3. < bindings> 
  4. < basicHttpBinding> 
  5. < binding name="NewBinding2MB" 
    maxReceivedMessageSize="2097152"> 
  6. < readerQuotas maxString
    ContentLength="2097152" /> 
  7. < /binding> 
  8. < /basicHttpBinding> 
  9. < /bindings> 
  10. < !-- add for the message size --> 
  11. < behaviors> 
  12. < serviceBehaviors> 
  13. < behavior name="Web.WCF.
    ShareServiceBehavior"> 
  14. < serviceMetadata httpGetEnabled="true"/> 
  15. < serviceDebug includeException
    DetailInFaults="false"/> 
  16. < /behavior> 
  17. < /serviceBehaviors> 
  18. < /behaviors> 
  19. < serviceHostingEnvironment aspNet
    CompatibilityEnabled="true"/> 
  20. < services> 
  21. < service behaviorConfiguration=
    "Web.WCF.ShareServiceBehavior" 
    name="Web.WCF.ShareService"> 
  22. < endpoint address="" binding=
    "basicHttpBinding" bindingConfiguration=
    "NewBinding2MB" contract="Web.WCF.ShareService"/> 
  23. < endpoint address="mex" binding=
    "mexHttpBinding" contract="IMetadataExchange"/> 
  24. < /service> 
  25. < /services> 
  26. < /system.serviceModel> 

网页名称:WCF字符串过长问题解决方法指南
文章路径:http://www.shufengxianlan.com/qtweb/news35/325585.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联