使用c#webservice的datetime列传递数据集 [英] Passing Datasets with datetime columns for a c# webservice

查看:172
本文介绍了使用c#webservice的datetime列传递数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#webservice(服务器)和C#windows窗体(客户端)。我的webservice方法接受数据集对象作为参数。数据集有2-3个数据表,表中有日期时间列。



客户端安装在不同的位置,当从客户端发送数据集时通过添加/减去日期时间偏移值来修改datetime列,因此网络服务器收到错误的日期。



我无法更改任何内容客户端,如何处理服务器端的问题(在Web服务中)。



我想要的是日期字段应该完全按照输入的方式传输客户端(如字符串数据类型)。



我使用访问数据库作为Windows窗体客户端的后端。从客户端导出数据时,客户端创建数据集(2-3个表)并将数据集传递给webservice方法。我调试了客户端,我认为在序列化过程中,日期时间偏移量被添加到datetime列。我想在反序列化期间删除偏移量。



示例:如果在客户端日期是01/01/2011,服务器将收到它为31/12 / 2010.



提前致谢

I have a C# webservice(server) and C# windows form(client). My webservice method accepts a dataset object as parameter. The dataset has 2-3 datatables, and in the tables there are datetime columns.

The client is installed in different locations, when the dataset is sent from a client the datetime columns are modified by adding/subtracting the datetime offset values, because of this the webserver is receiving the wrong dates.

I am not in a position to change anything on the client, how can I handle the issue on the server side (in web service).

All I want is that the date fields should be transferred exactly as entered at client(like string data type).

I am using access database as backend for windows forms client. When exporting the data from client, the client creates a dataset(2-3 tables) and passes the dataset to webservice method. I debugged the client and I think it is during the serialization, the datetime offset is added to datetime columns. I want to remove offset during de-serialization.

example: if at client the date is 01/01/2011, the server is receiveing it as 31/12/2010.

Thanks in advance

推荐答案

有两种方法



1.使用OUC-DateTime并始终在客户端转换为localtimezone

2.使用TimeZoneInfo类转换客户端/服务器特定时区



TimeZone类识别本地时区,可以在协调世界时(UTC)和当地时间之间转换时间。 TimeZoneInfo对象可以表示任何时区,TimeZoneInfo类的方法可用于将一个时区中的时间转换为任何其他时区中的相应时间。 TimeZoneInfo类的成员支持以下操作:



检索已由操作系统定义的时区。

枚举系统上可用的时区。

转换不同时区之间的时间。

创建一个尚未由操作系统定义的新时区。

序列化时区以便以后检索。
There are 2 approaches

1. UseUTC-DateTime and always convert to localtimezone at the client
2. Convert the client/server specific timezones using the TimeZoneInfo class

The TimeZone class recognizes local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A TimeZoneInfo object can represent any time zone, and methods of the TimeZoneInfo class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the TimeZoneInfo class support the following operations:

Retrieving a time zone that is already defined by the operating system.
Enumerating the time zones that are available on a system.
Converting times between different time zones.
Creating a new time zone that is not already defined by the operating system.
Serializing a time zone for later retrieval.


这篇关于使用c#webservice的datetime列传递数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆