WCF字符串如果过长该如何处理

开发 开发工具
在实际应用中,我们经常会遇到WCF字符串过程的一些问题。那么如何才能正确的解决这一问题呢。在这里将会做一个详细介绍。

WCF服务中,如果我们遇到了程序中的字符串过长的话,应该如何正确处理呢?在这里我们将会为大家详细介绍一下WCF字符串的相关应用技巧,以帮助大家解决在实际应用中出现的一些特定问题。#t#

编写基于WCF服务的程序时,向WCF服务端发送一长串的HTML源码,结果客户端收到提示如下:

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

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

客户端app.config修改:

  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" maxNameTableCharCount="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修改:

 

  1. < system.serviceModel> 
  2. < !-- add for the message size --> 
  3. < bindings> 
  4. < basicHttpBinding> 
  5. < binding name="NewBinding2MB" maxReceivedMessageSize="2097152"> 
  6. < readerQuotas maxStringContentLength="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 includeExceptionDetailInFaults="false"/> 
  16. < /behavior> 
  17. < /serviceBehaviors> 
  18. < /behaviors> 
  19. < serviceHostingEnvironment aspNetCompatibilityEnabled="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字符串过程的解决方法。

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-15 13:15:11

Ruby字符串

2009-12-21 18:39:24

WCF字符串过长问题

2023-03-09 12:21:38

2010-11-26 09:51:54

MySQL字符串

2012-07-03 11:18:20

运维disable tab

2022-04-12 07:32:40

引擎模式Spring策略模式

2010-07-14 16:35:52

Perl字符串处理函数

2010-08-04 11:23:15

Flex字符串

2023-02-02 08:56:25

线程池线程submit

2010-10-09 11:54:46

MySQL字符串

2010-07-19 15:07:46

Perl字符串处理函数

2010-08-26 12:12:19

LMHOSTS文件

2016-12-30 13:32:24

字符串算法代码

2009-11-26 16:26:32

PHP字符串mbstr

2019-08-12 14:25:09

编程算法PythonJavaScript

2020-05-12 08:53:15

JavaScript字符串处理库

2021-08-26 11:41:50

字符串String.jsVoca

2023-10-18 07:55:41

Python字符串

2010-11-26 11:20:31

MySQL字符串处理函

2019-05-09 15:31:23

攻击服务器安全
点赞
收藏

51CTO技术栈公众号