1

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?

Dinesh
  • 41
  • 5
  • .NET Core 2.0 supports references to .NET Framework assemblies so you should be able to use the SoapFormatter class to migrate your data. – Brad May 14 '18 at 00:59
  • @Brad : I have tried to reference it but because SoapFormatter have a dependency of System.Runtime i can't use that code. System.Runtime.Serialization is not been supported. – Dinesh May 14 '18 at 02:30
  • You should be able to write a .NET Framework program using SoapFormatter to migrate the data in the database. – Brad May 14 '18 at 06:15
  • Yes that would be the last step if we don't find any solution. We want to go on that path if nothing works. Any more suggestions? – Dinesh May 14 '18 at 06:33
  • In the line `var buffer = Convert.FromBase64String(piqBlob);`, is `piqBlob` the data from the database you're wanting to migrate? – Brad May 14 '18 at 11:53
  • Yes its the serialized data stored in the database. – Dinesh May 14 '18 at 15:16
  • Try converting the Base64 string into it's raw string by using `Encoding.UTF8.GetString(Convert.FromBase64String(piqBlob));`. This should give you the raw SOAP XML document that you can then deserialize into your required format. It's a manual process but it bypasses SoapFormatter. – Brad May 14 '18 at 23:37
  • Hi Brad, thanks i have tried that already but it returns me a very complex xml which have cross references. I ditched that path as that requires lot of maintanence. Meanwhile i have created a library which does that serialization for me. Its something similar to mono. Thanks for the help and I am closing this issue for now. – Dinesh May 15 '18 at 06:36

0 Answers0