How can i Replace the SoapFormatter Serialize and Deserialize with .net core 2.0?

2.3k views Asked by At

I am working on migrating an old wcf project to .net core 2.0. At some places the code uses SoapFormatter class to serialize and deserialize data in Soap format.The Soap Formatter is no more supported in .net core 2.0 so i need to replace the piece of code to start using XMLSerialization. There is already some data stored in database which is serialized using SoapFormatter so i can't migrate the already stored data. Is there any way i can serialize and deserialize the already existing data with Xml Serialization without breaking it?

The piece of code using deserialization using soapformatter is:

var buffer = Convert.FromBase64String(piqBlob);
---------

public UserQuestionAnswers Deserialize(byte[] buffer)
        {
        using (var stream = new MemoryStream(buffer))
        {
            var questionsAnswers =
                Serializer.Deserialize(stream) as BusinessProcesses.Authentication.UserQuestionAnswers;
            if (questionsAnswers == null) return null;

            var uQuestionAnswers = new UserQuestionAnswers
            {
                Domain = questionsAnswers.Domain,
                KeyLabel = questionsAnswers.KeyLabel,
                Username = questionsAnswers.Username,
                UserUid = questionsAnswers.UserUid,
                QuestionAnswers = (from item in questionsAnswers.QuestionAnswers
                                   where item != null
                                   select new QuestionAnswer
                                   {
                                       QuestionId = item.QuestionId,
                                       QuestionHash = item.QuestionHash,
                                       AnswerHmac = item.AnswerHMAC,
                                       QuestionText = string.Empty
                                   }).ToArray()
            };
            return uQuestionAnswers;
        }
    }

Please let me know if you need more information on this. I am also open to any third part library if have a good rating?

0

There are 0 answers