Web Service changing the DateTime information even though client and server are in same TimeZone

The Web Service seems to be changing the DateTime information in a DataSet so that the client receives values with an hour difference.

I am running VS 2008, code is compiled for .NET 2.0.

I have three projects in this solution (at least that need to be considered for this question).

      Data Access Layer connecting to Oracle (Class Library) (DAL)

      Web Service connecting to Data Access Layer (Web Service) (IIS local (attaching to process aspnet_wp.exe for debug))

      .NET Compact client connecting to Web Service (Windows Application - .NET Compact) (running on USA Windows Mobile 5.0 Pocket PC R2 Emulator (set as startup project)) (Client)

I have verified the time information in the same session for both layers by using this code:

      System.Diagnostics.Debug.WriteLine("DAL/Client Current DateTime: " + DateTime.Now.ToString());
      System.Diagnostics.Debug.WriteLine("DAL/Client IsDaylightSavingTime: " + DateTime.Now.IsDaylightSavingTime());
      System.Diagnostics.Debug.WriteLine("DAL/Client TimeZone DaylightName: " + TimeZone.CurrentTimeZone.DaylightName);
      System.Diagnostics.Debug.WriteLine("DAL/Client TimeZone: " + TimeZone.CurrentTimeZone.StandardName);
      System.Diagnostics.Debug.WriteLine("DAL/Client UTC: " + DateTime.UtcNow.ToString());

Here is the output of that code:

      DAL Current DateTime: 11/10/2008 3:41:24 PM
      DAL IsDaylightSavingTime: False
      DAL TimeZone DaylightName: Mountain Daylight Time
      DAL TimeZone: Mountain Standard Time
      DAL UTC: 11/10/2008 10:41:24 PM

      Client Current DateTime: 11/10/08 3:41:09 PM
      Client IsDaylightSavingTime: False
      Client TimeZone DaylightName: Mountain Daylight Time
      Client TimeZone: Mountain Standard Time
      Client UTC: 11/10/08 10:41:09 PM

Here is the code I used in each project to generate the following debug information:

            foreach (DataRow dr in dtbl.Rows)
            {
                if (dr["the_id"].ToString() == "123456789")
                {
                    string sDebugInfo = string.Empty;
                    foreach (DataColumn dc in dtbl.Columns)
                    {
                        sDebugInfo += dc.ColumnName + ": " + dr[dc.ColumnName] + "\n";
                    }
                    Debug.WriteLine(sDebugInfo);
                }
            }

Here is the result from that:

Debugging information generated in Data Access Layer with data coming from DB:

DATE1: 10/31/2008 11:45:00 AM
DATE2: 10/31/2008 10:30:00 AM

-----

Debugging information generated in Web Service (localhost) with data coming from Data Access Layer:

DATE1: 10/31/2008 11:45:00 AM
DATE2: 10/31/2008 10:30:00 AM

-----

Debugging information generated in Client with data coming from Web Service (localhost):

DATE1: 10/31/08 10:45:00 AM
DATE2: 10/31/08 9:30:00 AM

-----

I have looked around the internet however have not had much time to research this, so I hope it has not been covered here previously and I missed it :-|

I would like to know what is going and how to fix it?

Thanks!
IDJCAsked:
Who is Participating?
 
IDJCConnect With a Mentor Author Commented:
Yes, I agree extraneous, I cannot give out the entire source code unfortunately, however I have created a test project to duplicate this behavior and cannot :-|. This project originally was built in VS 2005 then converted to VS 2008, I am wondering if this process has something to do with, also I noticed this issue around the time when the Daylight savings time changed, which is also around when I converted it, perhaps there is a bug, I am not sure.

Ultimately, what I have done is replaced the DateTime columns in the DataTables with string columns.

I have posted the code, if anyone can improve on my workaround, I would like to award them the points!

:-)

Thanks!
private void SerializeDateTime(DataTable dtbl)
        {
            for (int i = (dtbl.Columns.Count - 1); i >= 0; i--)
            {
                if (dtbl.Columns[i].DataType.ToString() == "System.DateTime")
                {
                    dtbl.Columns.Add(dtbl.Columns[i].ColumnName + "_SERIALIZED", Type.GetType("System.String"));
                }
            }
 
            foreach (DataRow dr in dtbl.Rows)
            {
                foreach (DataColumn dc in dtbl.Columns)
                {
                    if (dtbl.Columns[dc.ColumnName].DataType.ToString() == "System.DateTime")
                    {
                        dr[dtbl.Columns[dc.ColumnName].ColumnName + "_SERIALIZED"] = (dr[dc.ColumnName].ToString().Trim() != string.Empty) ?
                            DateTime.Parse(dr[dc.ColumnName].ToString()).ToString("s") :
                            string.Empty;
                    }
                }
            }
 
            for (int i = (dtbl.Columns.Count - 1); i >= 0; i--)
            {
                if (dtbl.Columns[i].DataType.ToString() == "System.DateTime")
                {
                    string sHoldName = dtbl.Columns[i].ToString();
                    dtbl.Columns.RemoveAt(i);
                    dtbl.Columns[sHoldName + "_SERIALIZED"].ColumnName = sHoldName;
                }
            }
        }

Open in new window

0
 
jose_juanConnect With a Mentor Commented:
Hi,

it's extraneous... are you sure you have not a error?

send your complete server and client code (important code).

Good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.