如何序列化 Microsoft.AspNet.Identity.UserLoginInfo class?
how to serialize Microsoft.AspNet.Identity.UserLoginInfo class?
我在我的 WCF 服务中使用 Microsoft.AspNet.Identity.UserLoginInfo class。
但是,我收到以下错误 -
Type 'Microsoft.AspNet.Identity.UserLoginInfo' 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
由于 class 是在 Microsoft.Aspnet.Identity 库中提供的内置版本,并且还标记为密封的,因此在扩展它以使其在我的 WCF 服务中可访问方面我没有得到太多帮助。
如有任何帮助,我们将不胜感激。
谢谢
正如它所说的......你不能。 "Consider marking it with the DataContractAttribute attribute..." 具有误导性,因为除非您拥有源代码,否则您不能这样做。我假设您只想将一些具有几个属性的序列化对象发送回您的客户端。我会尝试将当前标识映射到可序列化对象并将其发回。
[DataContract]
public class MyUserLoginInfo
{
[DataMember]
public string LoginProvider { get; set; }
[DataMember]
public string ProviderKey { get; set; }
}
稍后...
//Return me to client
var loginInfo = new MyUserLoginInfo { LoginProvider = myIdentity.LoginProvider, ProviderKey = myIdentity.ProviderKey };
我在我的 WCF 服务中使用 Microsoft.AspNet.Identity.UserLoginInfo class。 但是,我收到以下错误 -
Type 'Microsoft.AspNet.Identity.UserLoginInfo' 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
由于 class 是在 Microsoft.Aspnet.Identity 库中提供的内置版本,并且还标记为密封的,因此在扩展它以使其在我的 WCF 服务中可访问方面我没有得到太多帮助。
如有任何帮助,我们将不胜感激。
谢谢
正如它所说的......你不能。 "Consider marking it with the DataContractAttribute attribute..." 具有误导性,因为除非您拥有源代码,否则您不能这样做。我假设您只想将一些具有几个属性的序列化对象发送回您的客户端。我会尝试将当前标识映射到可序列化对象并将其发回。
[DataContract]
public class MyUserLoginInfo
{
[DataMember]
public string LoginProvider { get; set; }
[DataMember]
public string ProviderKey { get; set; }
}
稍后...
//Return me to client
var loginInfo = new MyUserLoginInfo { LoginProvider = myIdentity.LoginProvider, ProviderKey = myIdentity.ProviderKey };