The formatter threw an exception while trying to deserialize the message in WCF
有一个WCF应用, 主要功能是存储doc, txt等类型文件到database,当文件的大小在16kb之内,调用WCF service能正常工作;但如果文件大小超出16KB之外, 它将抛出这样一个错误:
The remote server returned an unexpected response: (400) Bad Request.
经过在网上的查询, 需要在服务端添加配置maxReceivedMessageSize (可以参考这位朋友的文章http://www.cnblogs.com/Gyoung/p/3369316.html), 基于这位朋友发布的信息上,还需要注意定义binding name时需要与endpoint里的bindingConfiguration的名称一致,否则还是会出错。
<binding name="basicHttpBinding_IEmailUtility" closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" messageEncoding="Mtom"/>
开始我使用的binding类型是basicHttpBinding, 添加之后,会出现另外一个错误:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:oneEmail. The InnerException message was 'There was an error deserializing the object of type EmailHelperWCF.EmailContent. The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 237210.'. Please see InnerException for more details.
解决办法:
1. 改变binding类型到WSHttpBinding
2. 在Binding下添加<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647">, 看下面的第三行
<wsHttpBinding>
<binding name="WSHttpBinding_IEmailUtility" closeTimeout="00:10:00" receiveTimeout="00:20:00" sendTimeout="00:20:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" messageEncoding="Mtom">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</wsHttpBinding>
3. 最好在<behaviors>下添加<dataContractSerializer maxItemsInObjectGraph="2147483647"/>, 看下面的第8行
<behaviors>
<serviceBehaviors>
<behavior name="EmailHelperWCF.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
The formatter threw an exception while trying to deserialize the message in WCF的更多相关文章
- 使用Spire组件抛出异常The type initializer for 'spr857' threw an exception
使用Spire组件抛出异常The type initializer for 'spr857' threw an exception 我使用免费的Spire.Xls组件尝试去转换Excel文档到PDF文 ...
- System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
[15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...
- iOS - libc++abi.dylib: terminate_handler unexpectedly threw an exception
代码出现crash,报错:libc++abi.dylib: terminate_handler unexpectedly threw an exception 当我们很明确是某一块代码执行导致了错误, ...
- web项目引用Java项目,连接报错error HTTP Status 500 - Servlet execution threw an exception
错误信息 项目背景: 一个web项目引用一个java Project,项目中添加了引用,但是打开页面访问,总报500错误.提示:servlet初始化错误. 环境:Eclipse luna JDK: 1 ...
- System.TypeInitializationException: The type initializer for 'Mono.Unix.Native.Stdlib' threw an exception.
08-31 17:02:03: ### DEBUG ##########################System.TypeInitializationException: The type ini ...
- the type initializer for '' threw an exception
the type initializer for '' threw an exception 问题:程序启动时初始化主窗口类时,弹出该错误.调查:查看类的构造函数是否会有异常抛出.解决:去掉类的构造函 ...
- javax.servlet.ServletException: Servlet execution threw an exception 异常解决之一
配置JDBC连接的JDBC.properties文件不存在(那天很奇怪配置文件不存在了,我也没有去移动那个文件.诡异呀)也会导致这个异常. 然后就报javax.servlet.ServletExcep ...
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...
- Filter execution threw an exception 错误
Filter execution threw an exception 错误,我在web.xml中配置了一个filter用spring来解决懒加载的问题,为什么就会包这个错 java.lang.NoS ...
随机推荐
- [Locked] Shortest Distance from All Buildings
Shortest Distance from All Buildings You want to build a house on an empty land which reaches all bu ...
- Power Calculus 快速幂计算 (IDA*/打表)
原题:1374 - Power Calculus 题意: 求最少用几次乘法或除法,可以从x得到x^n.(每次只能从已经得到的数字里选择两个进行操作) 举例: x^31可以通过最少6次操作得到(5次乘, ...
- 怎么调试EXC_BAD_ACCESS错误
当你遇到了一个EXC_BAD_ACCESS错误,我通常会给开发者几个建议: 1.在可执行选项中设置NSZombieEnabled参数,这有时会帮缩小问题的范围: 2.运行apple的内存检测工具,如 ...
- Servlet线程安全
public class servletDemo1 extends HttpServlet { int i=0; public void doGet(HttpServletRequest reques ...
- LINUX curl GET 掉参数解决办法
LINUX curl GET 掉参数解决方法 url 为 http://mywebsite.com/index.php?a=1&b=2&c=3web形式下访问url地址,使用 $_GE ...
- js~fancybox为我们提供的iframe功能
对于fancybox我们已经耳熟能详了,一般用来到表单的弹框,提示弹框等,而今天,我们将分页列表也使用fancybox来实现一下,这东西听起来简单,但做起来还真不是那么回事,有事细节需要我们注意的,首 ...
- .NET常用的扩展方法整理
using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...
- 文字保护纱-Material Design
Ok,关于这个Material Design 都快被说烂了,他被开发者越来越熟悉的程度,却与市场上的单薄身影形成了鲜明的对比,以至于每当我提及Material Design时就像祥林嫂附身一样. 有些 ...
- STL——increment/decrement/dereference操作符
increment/dereference操作符在迭代器的实现上占有非常重要的地位,因为任何一个迭代器都必须实现出前进(increment,operator++)和取值(dereference,ope ...
- [转] 使用CodeViz生成C/C++函数调用关系图
运行环境:虚拟机下的Ubuntu 11.04 结合Graphviz工具,使用CodeViz可以生成直观和漂亮的C/C++程序函数之间的调用关系图. 1.安装graphviz 在安装CodeViz之前, ...