WCF服务对象序列化 [英] WCF Service object serialization
问题描述
我有一个名为contact的抽象类,另一个名为client的类继承自contact。我正在使用带有类型联系参数的方法处理WCF服务。
然而我所拥有的是我想传递的客户端实例。
Im面临此错误:
I have one abstract class named contact and another class called client that inherits from contact. I'm dealing with a WCF Service with a method that takes a parameter of type contact. however what I have is an instance of client that I want to pass. Im facing this Error:
输入数据合约名称为'Client:http:// schemas'的'xxx.Client'。 datacontract.org/2004/07/xxx'不是预期的。将任何静态未知的类型添加到已知类型列表中 - 例如,通过使用KnownTypeAttribute属性或将它们添加到传递给DataContractSerializer的已知类型列表中。
Type 'xxx.Client' with data contract name 'Client:http://schemas.datacontract.org/2004/07/xxx' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
推荐答案
WCF不直接用于抽象类。您应在datacontract或服务类上使用KnownType属性。以下是示例;
WCF does not directly works on abstract classes. You shall use KnownType attributes on the datacontract or service class. below are examples;
[DataContract]
[KnownType(typeof(Client))]
public class Contact
{
...
}
[ServiceContract]
[ServiceKnownType(typeof(Client))]
public interface IMyService
{
contact getcontact(Guid id);
}
这篇关于WCF服务对象序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!