1.调用服务时服务

当我们使用 Web Service 或 WCF 服务时,常把读取的数据转化为string类型(xml格式),当数据量达到一 定数量时,会出现以下异常:

错误:格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ (命名空间)进行反序列化时出错: InnerException 消息是“反序列化对象异常,读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。

2.原因及解决方案

WCF传输大数据时,因为WCF本身的安全机制导致的,限制了客户端与服务器资源传输大小,当传输的数据超过上限后会产生异常。

     发送大数据:在WCF服务端解决

NetTcpBinding binding =  new NetTcpBinding();

            binding.MaxReceivedMessageSize= 2147483647(更改这个数字) ;

     接收大数据:在WCF客户端解决

            NetTcpBinding binding =  new NetTcpBinding();

            binding.ReaderQuotas = new XmlDictionaryReaderQuotas()

{ MaxStringContentLength = 2147483647(更改这个数字) };

Web Service 调用时,在绑定代理端是,添加如下BasicHttpBinding:

 有两种方法处理:
  第一种:在调用时传入Binding参数。

    

 BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
{ MaxReceivedMessageSize = int.MaxValue,
MaxBufferSize = int.MaxValue,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{ MaxStringContentLength = }
}
DLTEST.ServiceReference2.CS_WebServiceSoapClient svs = new DLTEST.ServiceReference2.CS_WebServiceSoapClient(binding);

  第二种方法,改一下调用客户端的配置文件app.config

    增加binding节点下增加 readerQuotas节点控制

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CS_WebServiceSoap" >
<readerQuotas maxDepth="64" maxStringContentLength="8192000" maxArrayLength="16384000"
maxBytesPerRead="4096000" maxNameTableCharCount="16384000" />
</binding>
<binding name="CS_WebServiceSoap1" >
<readerQuotas maxDepth="64" maxStringContentLength="8192000" maxArrayLength="16384000"
maxBytesPerRead="4096000" maxNameTableCharCount="16384000" />
</binding>
<binding name="CS_WebServiceSoap2" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://10.0.0.251:100/WebService/CS_WebService.asmx"
binding="basicHttpBinding" bindingConfiguration="CS_WebServiceSoap"
contract="ServiceReference1.CS_WebServiceSoap" name="CS_WebServiceSoap" />
<endpoint address="http://localhost:90/WebService/CS_WebService.asmx"
binding="basicHttpBinding" bindingConfiguration="CS_WebServiceSoap1"
contract="ServiceReference2.CS_WebServiceSoap" name="CS_WebServiceSoap1" />
<endpoint address="http://localhost:3383/WebService/CS_WebService.asmx"
binding="basicHttpBinding" bindingConfiguration="CS_WebServiceSoap2"
contract="ServiceReference3.CS_WebServiceSoap" name="CS_WebServiceSoap2" />
</client>
</system.serviceModel>
</configuration>

  

Web Service 或 WCF调用时读取 XML 数据时,超出最大字符串内容长度配额(8192)解决方法的更多相关文章

  1. InnerException 消息是“反序列化对象 属于类型 *** 时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。(注意细节)

    WEB站点在调用我们WCF服务的时候,只要传入的参数过长,就报如下错误: 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: formD ...

  2. 读取 XML 数据时,超出最大字符串内容长度配额 (8192)

    格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://www.thermo.com/informatics/xmlns/limswebservice 进行反序列化时出错: Process ...

  3. WCF传送大数据时的错误“ 超出最大字符串内容长度配额”

    格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult.InnerException 消息是“反序 ...

  4. wcf序列化大对象时报错:读取 XML 数据时,超出最大

    错误为: 访问服务异常:格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出 错: request.InnerException 消息是“反序 ...

  5. 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大

    当遇到这个错误的时候郁闷了好长时间报错是字符串长度过大可是修改了MaxStringContentLength”属性的值却不起作用最后才发现还是因为配置文件配置的问题在服务端 格式化程序尝试对消息反序列 ...

  6. {"读取 XML 数据时,超出最大名称表字符计数配额(16384)。。。。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxNameTableCharCount 属性,。。

    这个问题倒腾了快一周,看了网上各种解决方案,还看了用谷歌翻译看了全英文的,参照了修改也没能够解决问题. 最后只有自己一行一行断点,一行一行删除代码,各种检测.主要是我在webservice里面新添加几 ...

  7. Web Service和WCF的区别。其实二者不属于一个范畴!!!

    Web Service和WCF的区别 [1]Web Service:严格来说是行业标准,也就是Web Service 规范. 它有一套完成的规范体系标准,而且在持续不断的更新完善中. 它使用XML扩展 ...

  8. ServiceStack Web Service 创建与调用简单示列

    目录 ServiceStack 概念 ServiceStack Web Service 创建与调用简单示列 上篇文章介绍了ServiceStack是什么,本章进入主题,如何快速简单的搭建Service ...

  9. Web Service和WCF的到底有什么区别

    [1]Web Service:严格来说是行业标准,也就是Web Service 规范,也称作WS-*规范,既不是框架,也不是技术. 它有一套完成的规范体系标准,而且在持续不断的更新完善中. 它使用XM ...

随机推荐

  1. Word2007视频教程

    超级好教程 http://v.youku.com/v_show/id_XMTAwOTgwNTIw.html 视频: oeasy教你玩转office系列之Word视频教程01 http://v.youk ...

  2. FILTER——JAVA

    一.概念 Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或 ...

  3. Android开之在非UI线程中更新UI

    当在非UI线程中更新UI(程序界面)时会出现例如以下图所看到的的异常: 那怎样才干在非UI线程中更细UI呢? 方法有非常多种.在这里主要介绍三种: 第一种:调用主线程mHandler的post(Run ...

  4. vue 去掉元素之间空格 preserveWhitespace

    preserveWhitespace 说明参考:https://vue-loader.vuejs.org/zh/options.html#compiler options: { compilerOpt ...

  5. Installing ODIConsole application using weblogic server

    在ODI 创建Java EE Agent时候, 启动Fusion Middleware配置向导创建新域的时候,选择的模板如下,已经包含了 Oracle Data Integrator - Consol ...

  6. 2、redis原生的命令操作不同数据类型

    一.常用数据类型简介: redis常用五种数据类型:string,hash,list,set,zset(sorted set). 1.String类型 String是最简单的类型,一个key对应一个v ...

  7. 整合ssm框架之配置文件

    原文:https://blog.csdn.net/zwyanqing/article/details/53039591 ssm整合 一.applicationContext.xml 1.配置数据源 & ...

  8. Centos7 安装 docker-ce

    本文参考官网地址:https://docs.docker.com/install/linux/docker-ce/centos/#os-requirements 1.卸载旧版本的docker $ su ...

  9. topshelf 开发windows 服务资料

    官方配置 http://docs.topshelf-project.com/en/latest/configuration/config_api.html#service-start-modes to ...

  10. 点击threadItem查看MessageList时传递数据

    @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {   ...