首页 > 解决方案 > 将对象传递给 WCF 端点

问题描述

我有一个 WCF 服务,它有一个服务方法,它接受一个 object[] 类型的参数。我想根据各种工作流程传递不同种类的对象。当我尝试传递从基本对象类型继承的任何具体对象时,我收到以下错误:

'Error in line 1 position 446. Element 
'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data of the 
'http://schemas.datacontract.org/2004/07/...' data contract. The deserializer has no knowledge of any 
type that maps to this contract. Add the type corresponding to '...' to the list of known types - for 
example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed 
to DataContractSerializer.'

问题

如何将任何类型的普通旧对象传递给 WCF 服务并在 WCF 服务方法中解释(转换为)我想要的类型?

在高层次上,我想做的是将普通类型对象的实例传递给 WCF。这甚至可能吗?

标签: c#wcfserialization

解决方案


推荐阅读