[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-10
2
Medium Priority
?
553 Views
Last Modified: 2013-11-17
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!
0
Comment
Question by:IDJC
2 Comments
 
LVL 5

Assisted Solution

by:jose_juan
jose_juan earned 400 total points
ID: 22928474
Hi,

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

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

Good luck!
0
 

Accepted Solution

by:
IDJC earned 0 total points
ID: 22997559
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question