WCF DataContract序列化异常 [英] WCF DataContract Serialization exception

查看:83
本文介绍了WCF DataContract序列化异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当WCF服务收到Soap请求时,出现此异常:


格式化程序尝试反序列化消息时引发异常:尝试反序列化参数 http://tempuri时出错. org/:myRequest . InnerException消息为``第1行位置1729错误.期望状态为'Element'..遇到了名称为'',名称空间为''的'文本'. '.有关更多详细信息,请参见InnerException.

有人碰到这个吗?

唯一与此有关的是消息包含一个由Mtom编码管理的base64编码的字节数组.

我最初的猜测是请求被截断有问题,但是我已经执行了以下步骤以确保这不是问题:

1)已添加< dataContractSerializer maxItemsInObjectGraph =''2147483647''/>对我的服务行为的影响是
2)在< readerQuotas maxDepth =" 2147483647"中添加了maxArrayLength ="2147483647"; maxBytesPerRead ="2147483647"; maxNameTableCharCount ="2147483647"; maxStringContentLength ="2147483647"/>绑定到我的绑定

都解决了问题.

当我在客户端上进行跟踪时,它会正确创建消息.在对服务进行跟踪时,会发生异常.但是,不会记录该消息(但是会记录发送到该服务的其他消息).

有什么想法吗?

解决方案

要记录消息,也应启用消息记录功能.您能否将消息传递跟踪源添加到配置文件中,如下面的帖子中所示

http://tempuri.org/:myRequest. The InnerException message was 'Error in line 1 position 1729. Expecting state 'Element'.. Encountered 'Text'  with name '', namespace ''. '.  Please see InnerException for more details.

Has anyone run into this?

The only unique thing about this is the fact that the Message contains a base64 encoded byte array that is being managed by the Mtom encoding.

My initial guess is that there's a problem with the request being truncated, but I've already performed the following steps to make sure that isn't an issue:

1)  Added <dataContractSerializer maxItemsInObjectGraph="2147483647"/> to my service's behavior
2) Added <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> to my binding

either has fixed the problem.

When I do a trace on the client, it creates the message correctly.  When I do a trace on the serive, the exception occurs.  However, the message is not logged (other messages sent to the service are logged, though).

Any Ideas?

解决方案

to log the message, message logging should be enabled as well. Could you add the messaging trace source to your config file as shown in the post below  

http://msdn.microsoft.com/en-us/library/ms730064.aspx


这篇关于WCF DataContract序列化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆