我有工作流程服务。我还在该服务中使用工作流持久性。但是我在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.
我尝试过关于这个例外的研究,但我找不到任何东西。
如何解决这个问题?或者让我知道上述例外的原因是什么?
答案 0 :(得分:4)
System.ServiceModel.Channels.ReceivedFault
是一个不可序列化的内部 .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);
}