tags:

views:

249

answers:

2

Sorry if this issue has been beaten to death, but I can't seem to find a good answer to my question.

I have written a .NET 2.0 client that consumes a web service. The web method I call returns several DateTime values in UTC format.

It appears that the values are being deserialized as DateTimeKind.Local. I assume this is the default behavior for the .NET SOAP framework. However, I need the values to be DateTimeKind.Unspecified.

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

A: 

This is what I've found on MSDN:

When using the .NET Framework version 1.0 and 1.1, DO NOT send a DateTime value that represents UCT time thru System.XML.Serialization. This goes for Date, Time and DateTime values. For Web services and other forms of serialization to XML involving System.DateTime, always make sure that the value in the DateTime value represents current machine local time. The serializer will properly decode an XML Schema-defined DateTime value that is encoded in GMT (offset value = 0), but it will decode it to the local machine time viewpoint.

I do not know if this is still true for .NET 2.0

This is the link to the article.

Frederik Gheysels
+1  A: 

Update:

The DateTime values are not being sent in UTC like I thought. They are local times with the time zone offset.

However, my problem still remains: I need the DateTime values to be deserialized without the time zone offset. I want the times in their local time zone, not converted to my time zone.

I found a work-around, though. It turned out to be pretty easy to write a SoapExtension descendant to remove the time zone information from all xs:dateTime values.

Jamin