473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

capture TimeZone of DateTime passed to web service?

I want to create a web service that allows the caller to pass a DateTime to
the web service (that is, create a web method such as void
MyWebMethod(DateTime dt).) However, I want to be able to capture the
TimeZone of the caller as well - but I don't want the interface to specify an
xs:string as the method argument - I want it to use an xs:dateTime type
argument.

Now, I know when a DateTime structure is serialized into XML it becomes an
xs:dateTime type, and it is always formatted using the full ISO 8601 format,
including the offset to UTC for the sending computer (such as
"2005-08-24T01:02:03+08:00", where the offset to UTC is +8 hours in this
example.) When the web service receives the call, the xs:dateTime is
automagically deserialized back into a DateTime structure (probably by the
framework internally calling DateTime.Parse()), which converts the string
into the correct local time using the receiving computer's TimeZone.

Is there (with attributes?) to get at the raw string that comes in with the
method call, for a primative type such as DateTime? I know I could change
the param type to string, but I want to let the caller know that they should
only pass dateTimes, not arbitrary strings. I tried using
XmlElementAttribute to specify the argument use xs:dateTime with a .Net type
of System.String, but it gives me an error.

Any ideas? Thanks!
Nov 23 '05 #1
3 8296
I think the best idea is to add a xs:string parameter or add a parameter
for TimeZone, these should be easy ways. Otherwise, you have to get the raw
soap message on server side and analyst the string like
"2005-08-24T01:02:03+08:00" to get TimeZone infomation. To do this, you may
need to use SoapExtension:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwebservicesprotocolssoapextensionclasst opic.asp

Luke
Nov 23 '05 #2
Thanks for your reply, Luke. I have a couple follow-up questions:

1) Without using SoapExtensions, is there no other way to have the web
method interface & WSDL specify xs:dateTime, but have the element delivered
to the c# code as an xs:string? It seems that a string format would always
be possible, as that really is the native format the data is sent as. Is
there no attribute (like XmlElementAttribute) that can achieve this?

2) You mention adding a TimeZone parameter: could you elaborate on this
idea? I had been considering trying to have the caller send their
TimeZone.CurrentTimeZone object (which is serializable, and seems to
serialize the offset to UTC and the timezone string labels - such as "EST" -
but doesn't seem to serialize the daylightsavings info), but I thought I read
somewhere that a given PC can only have a TimeZone object that represents the
current local time zone, not another timezone. If I can fully utilize the
TimeZone object from another timezone, that would be perfect.

Or, maybe you were thinking more of some sort of globally-recognized
standard string timezone identifier? If so, how would I utilize that? I
have seen some third-party classes that might be able to make use of such a
string.

Thanks,
-A

"[MSFT]" wrote:
I think the best idea is to add a xs:string parameter or add a parameter
for TimeZone, these should be easy ways. Otherwise, you have to get the raw
soap message on server side and analyst the string like
"2005-08-24T01:02:03+08:00" to get TimeZone infomation. To do this, you may
need to use SoapExtension:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwebservicesprotocolssoapextensionclasst opic.asp

Luke

Nov 23 '05 #3
(1) I am afraid that there is no attribute which can be set on a parameter
in a web method.

(2) A TimeZone is just passed as a value, like a string or integer, it will
do nothing with TimeZone on the server. And you can pass a integer or a
string to the web server for client timezone, for example, "8" or "+8".

Luke
Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
1
by: Adam Monsen | last post by:
Say I have the following datetime object: >>> from datetime import datetime >>> d = datetime(2005, 8, 10, 15, 43) I happen to know this is a local time from the Netherlands, so I assume the...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
5
by: Iwan Petrow | last post by:
Hi, I have Win application -> Web service -> Sql Server. The user input date and time in format dd/MM/yy hh:mm. I convert it to datetime and send it to a web service which save it to the db. But...
6
by: Bijoy Naick | last post by:
I have an events table which stores the time of each event - the time and assoicated timezone. Is there a way of converting this time into GMT (with support for DST).. some sort of function which...
2
by: Navin Mishra | last post by:
Hi, Can a web service method return safely a DateTime value ? Would it cause problems for non-.NET client proxy generators ? Thanks Navin
0
by: David Pratt | last post by:
Hi. I am creating a couple of small methods to help me manage time from UTC as standard but I am getting strange results. If I start with a datetime of 2005-12-12 14:30:00 in timezone...
2
by: Michele Locati | last post by:
Hi to everybody I'm working with dates and time, and I can't find the way to determine the time in a generic TimeZone. Here's an example of what I'd like to do: // I get the local date and...
4
by: reach2raziq | last post by:
Hi All, I have one web site and server that is hosted on "Pacific Standard Time" Zone . When a user from different contries creat blogs the displayed time for respective blog will be a server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.