【问题标题】:How to fix 'System.ServiceModel.Channels.ReceivedFault' cannot be serialized如何修复“System.ServiceModel.Channels.ReceivedFault”无法序列化
【发布时间】:2015-11-26 03:52:24
【问题描述】:

我有一个工作流服务。我还在该服务中使用工作流持久性。但是在 IIS 中部署工作流后,我在服务器上的日志文件中从客户端向工作流服务发出请求。我看到一条消息

The execution of the InstancePersistenceCommand named {urn:schemas-microsoft-com:System.Activities.Persistence/command}SaveWorkflow was interrupted by an error.InnerException Message: Type 'System.ServiceModel.Channels.ReceivedFault' cannot be serialized.
Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.

我尝试对此异常进行研究,但没有找到任何东西。

如何解决这个问题?或者让我知道上述异常的原因是什么?

【问题讨论】:

  • 您是否尝试过错误消息提示的内容?
  • 工作流服务中的每个服务方法,我都有try catch,但我没有从中得到任何东西。
  • 你看,你的一个类型暴露了一个'System.ServiceModel.Channels.ReceivedFault'类型的属性,它不能被序列化,因为这个类没有用DataContractAttribute属性标记,所以它不能被序列化.所以将该属性标记为忽略。

标签: wcf workflow workflow-foundation-4 workflowservice


【解决方案1】:

System.ServiceModel.Channels.ReceivedFault 是一个不可序列化的internal .NET 框架类,因此很遗憾,您无法纠正实际的根本原因(即,使所述类可序列化)。

您可能正在通过 WCF 调用出现错误的外部服务,即抛出 System.ServiceModel.FaultException。 IIRC,在FaultException 对象的深处,是对罪魁祸首的引用,ReceivedFault 实例。

解决方法:捕获所有FaultExceptions,将FaultException中需要知道的信息转成可序列化的异常,然后抛出后者:

try
{
    CallService();
}
catch (FaultException ex) 
{
    // Gather all info you need from the FaultException
    // and transport it in a serializable exception type.
    // I'm just using Exception and the message as an example.
    throw new Exception(ex.Message);
}

【讨论】:

    猜你喜欢
    • 2015-03-17
    • 2011-09-21
    • 1970-01-01
    • 2019-03-07
    • 2019-06-24
    • 2016-07-23
    • 2017-02-27
    • 1970-01-01
    • 2013-04-04
    相关资源
    最近更新 更多