Search
Closed
as Won't Fix Help for as Won't Fix

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 488856
Opened: 9/9/2009 7:54:00 AM
Access Restriction: Public
0
Workaround(s)
1
User(s) can reproduce this bug
Hi!

I'm using WCF with SQL Server 2008. Briefly; WCF changes the DateTime values in a DataSet by the difference of the timezones of the client and the server.

For example one of your columns is SQL DATE type and returns "2009-09-08" but at the client side it returns to "2009-09-08 03:00:00"
Details (expand)

Product Version

.NET Framework 3.5 SP1
Product Language
English

Operating System
Windows Vista RTM/SP1/SP2
Operating System Language
English

Architecture
x86

Priority
(1=blocking, 2=important, 3=nice to have)
2

Severity
(1=major functionality issue, 2=important functionality issue, 3=nice to have)
1

Steps to Reproduce
1. Create a WCF method that returns a DataSet which includes a DateTime column.
2. Call that WCF method from a machine that is on a different time zone than the WCF Server.
Actual Results
WCF adds the timezone difference to the DateTime values in the DataSet therefore even a simple SQL DATE column value is shifted.
Expected Results
WCF at least should not carry a conversion that the developer cannot modify. Or give the chance to edit the properties so as the DataSet is transferred as "Local to Local" or "UTC to UTC" latter of which seems more logical.
Component Usage
(any information on your scenario that may help in investigating your issue)
 

How often does this happen?
Always Happens

Have you seen this problem in other versions?
I don't know if this issue existed previously
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 9/10/2009 at 2:05 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 9/17/2009 at 4:59 PM
Hi,

Can you give me some more information about the issue you are seeing. As I understand it, you have a db, a server and a client. On the server you get a dataset from a data adapter. You then return the dataset as an operation return type to the client. Is this correct.

So, I don't think the presence of the database or the dataset itself is important. Once WCF has the datetime in memory, it is just a regular CLR datetime instance. WCF will then serailize it just like it would serialize any datetime. WCF does not truncate the timezone info when it serializes a datetime, and I think if you were to look at the body of the outgoing/incoming messages you would see this.

Most likely you just need to check the datetime kind property of the instances on the server and the client. You'll either find that they are both local or one is local and the other is universal. The simple fix is to call dateTime.ToUniversalTime() or dateTime.ToLocalTime() as needed.

Please let me know if that doesn't resolve your issue.

Thanks

Posted by Someguyonabox on 9/18/2009 at 2:42 PM
http://msdn.microsoft.com/en-us/library/system.data.datasetdatetime(VS.80).aspx

Basically, I think the default DateTimeMode ( which can be edited on a datetime column in the dataset designer ) should default to a time mode that does not apply an offset on serialization. I think that is the issue, when you serialize, by default NO OFFSET should be applied. But the default datetimemode in a dataset designer is to UnspecifiedLocal, which applies an offset.

You can ( at least you should be able to ) change the default DateTimeMode in the dataset designer, and get the correct serialization behavior.

Posted by Zubeyir on 10/6/2009 at 1:47 AM
Sorry for coming back late.

For "Posted by Microsoft on 9/17/2009 at 4:59 PM
So, I don't think the presence of the database or the dataset itself is important. Once WCF has the datetime in memory, it is just a regular CLR datetime instance. WCF will then serailize it just like it would serialize any datetime. WCF does not truncate the timezone info when it serializes a datetime, and I think if you were to look at the body of the outgoing/incoming messages you would see this. "

When it's a single DataTime variable then you're correct and it's not a bit of problem. But when it's a DataTime column in a DataTable that comes from a DB server that is on a different TimeZone that's a problem because I have no control on the DataTime column within the DataTable. WCf automatically applies a time shift and I have no option to avoid it. There are some cases that you may want to turn off that feature. I totally like the feature but there has to be an option to control the behaviour.

Thanks.
Posted by Zubeyir on 10/9/2009 at 5:33 AM
Hi again!

I think I should give another example.

Assume we have a SQL Server at GMT -2 and a client at GMT +2. The SQL Server produces a DataTable within a DataSet. This DataTable contains a Colunm of type DATE. This column is popılated with a value "2009-10-11". After this DataSet is transferred over WCF, as a result of time difference, the client at GMT +2 read "2009-10-11 04:00:00".

That is the situation. Since I cannot modify the behaviour of WCF at this point, my client receives shifted Date values.

Thanks.
Posted by Microsoft on 10/15/2009 at 12:18 PM
To be clear, this is not a WCF issue, but a serialization issue with regards to the .NET DateTime type. WCF simply takes a type and serializes it as the type tells it to. WCF certainly doesn’t change the value of the types in way. See this post from back in 2004 with regards to the Datetime serialization: http://blogs.msdn.com/brada/archive/2004/04/13/112784.aspx.

As Someguyonabox mentioned in a previous post, the creators of DataTable were aware of this DateTime serialization issue and provided the DateTimeMode property on the DataColumn type. The default for this happens to be DataSetDateTime.UnspecifiedLocal, which will create the timeshift that you see when the DateTime is serialized and then deserialized. However, you can change the DateTimeMode property to DataSetDateTime.Unspecified (See http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datetimemode.aspx), and you will not see the timeshift anymore.

Of course, in order to change the DateTimeMode property value, you will need to enumerate thru the tables in your DataSet, and then thru the columns of each table, looking for columns of type DateTime and setting the DateTimeMode. You would need to do this within your WCF operation, after you’ve gotten the DataSet from the data provider. You could also create a custom WCF parameter inspector that could perform this for each parameter of type DataSet that it sees in the outgoing response.
Posted by Zubeyir on 10/16/2009 at 4:46 AM
Thank you for this clear explanation! And thank you Someguyonabox for you brillant participation too. I'll make changes to the application as you suggested.

Regards,
Zubeyir
Posted by JocularJoe on 11/9/2009 at 11:11 AM
This looks very similar to https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=349215

In Zubeyir's example of a SQL Server DATE column, there's an argument that this should be serialized as xs:Date without any time zone offset.
Posted by Zubeyir on 11/17/2009 at 4:03 AM
Thanks Joe. This is another way to the same problem.