我在服务器端收到 WCF 错误:
尝试序列化参数http://tempuri.org/:GetUserResult时出错。InnerException 消息是 'Type 'RoleProxy' with data contract name RoleProxy:http://schemas.datacontract.org/2004/07/' 不是预期的。...
我的问题是,我没有任何可以序列化的 RoleProxy 类型。
我有以下课程:
[DataContract]
[KnownType(typeof(Permission))]
public class Role
{
protected virtual long _ID { get; set; }
[DataMember]
public virtual long ID
{
get { return _ID; }
// zum Test
set { _ID = value; }
}
[DataMember]
public virtual string Name { get; set; }
[DataMember]
public virtual bool IsDefault { get; set; }
[DataMember]
public virtual ICollection<Permission> Permissions { get; set; }
public Role()
{
}
public Role(string name, ICollection<Permission> permissions, bool isDefault = false)
{
Name = name;
Permissions = permissions;
IsDefault = isDefault;
}
public virtual bool HasPermission(Permission perm)
{
foreach(Permission permission in this.Permissions)
if (permission.Equals(perm))
return true;
return false;
}
public virtual bool Equals(Role other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other.Name, Name);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof(Role)) return false;
return Equals((Role)obj);
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
public override string ToString()
{
return Name;
}
}
这是我正在调用的函数:
[ServiceContract]
[ServiceKnownType(typeof(Role))]
[ServiceKnownType(typeof(User))]
[ServiceKnownType(typeof(Permission))]
[ServiceKnownType(typeof(IList<Role>))]
[ServiceKnownType(typeof(IList<User>))]
[ServiceKnownType(typeof(IList<Permission>))]
public interface ISecurityManager
{
...
[OperationContract]
User GetUser(string userDomain, string userName);
...
}
服务器正确接收了结果,但是我找不到一些序列化问题。有什么解决办法吗?
谢谢。