Search code examples
wcfserializationasp.net-identitydatacontract

how to serialize Microsoft.AspNet.Identity.UserLoginInfo class?


I am using Microsoft.AspNet.Identity.UserLoginInfo class in my WCF service. However, I am getting following error -

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

As the class is in-build provided in Microsoft.Aspnet.Identity library, and also marked as Sealed, I am not getting much help on extending that to make it accessible within my WCF service.

Any help on this will be much appreciated.

Thanks


Solution

  • As it says... you can't. The "Consider marking it with the DataContractAttribute attribute..." is misleading since you CAN'T do this unless you have the source code. I'm assuming that your just want to send some serialized object with a couple properties back to your client. I'd try to just map the current identity to a serializable object and send it back.

    [DataContract]
    public class MyUserLoginInfo
    {
        [DataMember]
        public string LoginProvider { get; set; }
    
        [DataMember]
        public string ProviderKey { get; set; }
    }
    

    The later on...

    //Return me to client
    var loginInfo = new MyUserLoginInfo { LoginProvider = myIdentity.LoginProvider, ProviderKey =  myIdentity.ProviderKey };