DateTime Xml Deserialization

Sorry if this issue has been beaten to death, but I cannot find a good answer to my question.

I wrote a .NET 2.0 client that uses a web service. The Web method I am calling returns multiple DateTime values โ€‹โ€‹in UTC.

It looks like the values โ€‹โ€‹are deserialized as DateTimeKind.Local. I am assuming this is the default behavior for the .NET SOAP framework. However, I need DateTimeKind.Unspecified values.

What are my options for overriding the deserialization of these DateTime values?

+2


source to share


2 answers


This is what I found on MSDN:

If you are using the 1.0 and 1.1 versions of the .NET Framework, DO NOT send a DateTime value that represents the UCT time through System.XML.Serialization. This happens for date, time, and date values. For web services and other forms of serialization using XML System.DateTime, always make sure that the value in the DateTime value represents the current local time of the machine. The serializer will correctly decode DateTime values โ€‹โ€‹defined in the XML schema that are encoded in GMT (offset value = 0), but it will decode it at the local machine time point.



I don't know if this is true for .NET 2.0

This is a link to the article.

+1


source


Update:

DateTime values โ€‹โ€‹are not sent in UTC as I thought. They are local time with a time zone offset.



However, my problem still remains: I need the DateTime values โ€‹โ€‹to be deserialized without offsetting the timezone. I want the time to be in their local timezone, not my timezone.

I found a workaround though. It was pretty easy to write a descendant of SoapExtension to remove timezone information from all xs: dateTime values.

+1


source







All Articles