'System.ServiceModel.Channels.ReceivedFault'无法序列化如何解决
How to fix 'System.ServiceModel.Channels.ReceivedFault' cannot be serialized
我有工作流服务。我还在该服务中使用工作流持久性。但是在 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.
我尝试研究这个异常,但我没有找到任何东西。
如何解决这个问题?或者让我知道上述异常的原因是什么?
System.ServiceModel.Channels.ReceivedFault
是不可序列化的 内部 .NET 框架 class,因此很遗憾,您无法纠正实际的根本原因(即使 class 可序列化)。
您可能正在通过 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);
}
我有工作流服务。我还在该服务中使用工作流持久性。但是在 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.
我尝试研究这个异常,但我没有找到任何东西。
如何解决这个问题?或者让我知道上述异常的原因是什么?
System.ServiceModel.Channels.ReceivedFault
是不可序列化的 内部 .NET 框架 class,因此很遗憾,您无法纠正实际的根本原因(即使 class 可序列化)。
您可能正在通过 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);
}