简体   繁体   English

从WCF服务获取无效的日期时间值

[英]Getting invalid datetime values from WCF service

I have a WCF service and a windows application, both on different time-zones. 我有一个WCF服务和一个Windows应用程序,它们都位于不同的时区。 Now this windows application saves and retrieve data through WCF service. 现在,此Windows应用程序通过WCF服务保存和检索数据。

When i do a bulk insert for a table having a column as logtime of datatype as datetime, i am able to save this local datetime in the database, but when i try to retrieve this table, it gives all wrong values of logtime column. 当我对具有列作为数据类型的日志时间作为日期时间的表的表进行批量插入时,我能够将此本地日期时间保存在数据库中,但是当我尝试检索该表时,它将给出logtime列的所有错误值。

Found many similar question on SO, but i can't implement UTC time, since the table i am referring to contains a thousand records, which keeps updating every 5-10 seconds. 在SO上发现了许多类似的问题,但是我无法实现UTC时间,因为我要引用的表包含一千条记录,每5-10秒会更新一次。

Is there any way to stop this automatic datetime conversion done by WCF service. 有什么方法可以停止由WCF服务完成的此自动日期时间转换。

Please guide. 请指导。

What does this mean: "it gives all wrong values of logtime column." 这是什么意思:“它给出了logtime列的所有错误值”。 Is the time the local time of the database server? 时间是数据库服务器的本地时间吗? And that's not what you want? 那不是你想要的吗?

I'm assuming you want the logtime column to be the time zone of the client machine. 我假设您希望logtime列为客户端计算机的时区。 Is that right? 那正确吗? And I'm also assuming, since it's not specified, that you're setting the logtime column using the default value of GetDate() within SQL Server. 而且我还假设,由于未指定,因此您正在使用SQL Server中的GetDate()的默认值设置logtime列。 I'm also assuming, since it's not specified, that you're using SQL Server. 我还假设,由于未指定,因此您正在使用SQL Server。

If you want to use the time zone of the client, then you have a few options: 如果要使用客户端的时区,则有几种选择:

  1. Change the time zone of the database server to the same time zone as the client machine. 将数据库服务器的时区更改为与客户端计算机相同的时区。
  2. Pass the time, to the WCF service, as a parameter. 将时间作为参数传递给WCF服务。 (I'm assuming the WCF service is running on a server in the same time zone as the database server.) (我假设WCF服务在与数据库服务器相同时区的服务器上运行。)
  3. Leave it as is, but convert to the right time zone when retrieving the data. 保持原样,但在检索数据时转换为正确的时区。

There may be some more options, but it would be helpful if you clarified the assumptions I made. 可能还有更多选择,但是如果您弄清楚我所做的假设,将会很有帮助。

What do you mean by this: "automatic datetime conversion done by WCF service?" 这是什么意思:“由WCF服务完成的自动日期时间转换?” Is it using its local time zone for the time? 是否在使用其当地时区? If so, then you'll need to have it accept a time, instead of determining it itself. 如果是这样,那么您需要让它接受时间,而不是自己确定时间。 Perhaps you should show some code. 也许您应该显示一些代码。 That would be helpful. 那会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM