我知道这个问题已经出现过几次,但没有一个答案对我有帮助。 我在C#中有DLL库,其中包含仅具有属性和枚举的MyType.cs类。
现在我想在WcfService中使用它。所以我添加了这样的序列化属性:
[DataContract]
[KnownType(typeof(Enum1))]
[KnownType(typeof(Enum2))]
public class MyType
{
[DataMember]
public Enum1 Property1 {get; set;}
[DataMember]
public Enum2 Property2 {get; set;}
}
[DataContract]
public enum Enum1 { [EnumMember] First = 0, [EnumMember] Second = 1};
[DataContract]
public enum Enum2 { [EnumMember] First = 0, [EnumMember] Second = 1};
现在我在我的Wcf服务中使用它:
[ServiceContract]
[ServiceKnownType(typeof(Enum1))]
[ServiceKnownType(typeof(Enum2))]
public interface IService
{
[OperationContract(Name = "GetSomeValue")]
bool GetSomeValue(Enum1 argument);
[OperationContract(Name = "GetSomeValue2")]
bool GetSomeValue2(out MyType outparameter);
}
当我运行它时,我得到的异常是MyType未在WCF服务中加载。我做错了吗?