When we talk about Web Services then it is obvious that there is a chance where the Web Service is hosted in different geographical location than its clients. Web service hosted in a server with different timezone from its client may not return expected data if the DateTime
input parameter is not properly configured/set.
Let us assume that we are trying to access a web service which is hosted in a server with different timezone as we are in. Also the service we are trying to access requires us to send input parameters of type DateTime
and based on that input values server will return us some data. In my case I was trying to access a QaaWS (Query as a Web Service) service from Bangladesh (locale en_US, timezone +6 hrs) hosted in a server in Netherlands (locale nl_NL, timezone: +1 hrs) that expects two date values as input parameters along with some other parameters.
In this case to retrieve expected data from the Web Service or QaaWS service we must send the data time parameter values in the format based on our locale. So that, the server that receives that date value can convert the value based on its own timezone.
DateTime
instances in C# .NET has a Kind
field that indicates whether the time value is based on local time, Coordinated Universal Time (UTC), or neither. So to retrieve expected data from the Web Service we must change its kind to DateTimeKind.Local
.
You can visit this for more information on DateTime.SpecifyKind()
.
In my case I was to send a date range for which I wanted to retrieve data. The c# code that I used to is give below.
// other codes above DateTime fromDate = new DateTime(fromYear, fromMonth, fromDay, 0, 0, 0, 001, DateTimeKind.Local); DateTime toDate = new DateTime(toYear, toMonth, toDay, 23, 59, 59, 999, DateTimeKind.Local); Rows[] rows = ws.runQueryAsAService(username, password, fromDate, toDate, other, params, here); // Other codes continued....