2

I have an existing .NET Framework WCF service which returns data serialized using the NetDataContractSerializer, this is consumed by various .NET Framework clients.

I now want to write a new client application which will also consume it, but my new client will be written in .NET Core.

The Windows Compatibility Pack for .NET Core provides most of the APIs necessary to consume WCF services, however this key NetDataContractSerializer class seems to be missing.

Is there any way of deserialising this data into a .NET Core app? The types themselves are in a shared .NET Framework assembly which happens to be .NET Standard compatible so that can be loaded in the .NET Core app no problem.

gallivantor
  • 1,091
  • 2
  • 14
  • 21

3 Answers3

2

It seems like this is not possible, therefore I have opened this issue on the .NET Core github to track this feature:

https://github.com/dotnet/corefx/issues/33120

gallivantor
  • 1,091
  • 2
  • 14
  • 21
0

While NetDataContractSerializer not available in .Net Core you can try this port of NetDataContractSerializer library. This is almost complete .Net Core port of .Net Framework System.Runtime.Serialization library.

Dmitry Kolchev
  • 2,116
  • 14
  • 16
-1

As you know, the NetdataContractSerializer class is not be supported by the DotnetCore. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.netdatacontractserializer?view=netframework-4.7.2
DataContractSerializer is supported by the dotnetcore and we could use the ReadObject method to read the Stream and return the deserialized object.

Product p1 = (Product)serializer1.ReadObject(ms);

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=netcore-2.1
For these cross-platform projects, I suggest you use the NewtonSoft.Json library which only depend on the .Net Standard.
https://www.nuget.org/packages/Newtonsoft.Json/

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • are you saying that DataContractSerializer can correctly deserialize data that was seiralized by the NetDataContractSerializer? – gallivantor Oct 29 '18 at 02:09
  • yes, I have made a test, but i don't suggest you follow that. – Abraham Qian Oct 29 '18 at 02:27
  • This doesn't work for me, I get `Element ClassName from namespace cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML` when trying to deserialize it using the DataContractSerializer – gallivantor Oct 30 '18 at 01:05
  • Yes, you're right. Given that the platform's incompatibility with serializer, I recommend you use the Newtonsoft.JSON. – Abraham Qian Nov 02 '18 at 03:30
  • unfortunately this is attempting to call into an existing WCF service, changing the way it serializes its data isn't really an option. Might have to abandon .NET Core and go back to Framework to get around this... – gallivantor Nov 02 '18 at 04:10
  • Yes, I could not agree you more. Officials describe the difference(above reference): The NetDataContractSerializer differs from the DataContractSerializer in one important way: the NetDataContractSerializer includes CLR type information in the serialized XML, whereas the DataContractSerializer does not. Therefore, the NetDataContractSerializer can be used only if both the serializing and deserializing ends share the same CLR types – Abraham Qian Nov 02 '18 at 05:39