.NET Framework Bookmark and Share   
 index > ASMX Web Services and XML Serialization > Passing DateTime parameter, pros and cons?..
 

Passing DateTime parameter, pros and cons?..

I was wondering for best practices here and couldn't find a suitable answer..

What do you thing about passing datetime (or timespan) as a parameter to a web method? Pros and cons and what to use if not datetime (string?? what format??) ?

I have recently written a web service, the web method had a datetime parameter and I hadseveral issues with that:

1.Time difference issues
I think that in my case it wasbetter to send delta time (timespan), by doing so, differences in time between the client and the server (if the time is taken from the local machine) can be avoided (the machines clock not syncronized).

2.Platform compatibility
I had to write an unmanaged client, I didn't know how date time was parsed and serialized, my client proxy obviously didn't know date time object and passed a string (the proxy was created using sproxy.exe). So using a sniffer I saw time looked like: "2008-06-23T13:14:28.4832978+01:00" when passes from a managed client passing datetime, so I formatted my time on the unmanaged client to this format.
However this seems like a to fur fetched solution and was wondering what do you think? What's the best way to pass date and time in web services? should it be local (since I think passing dateTime already handles time zones) or UTC\GMT? what format?

bbb-bbb
Hi,
There is some great guidance on working with DateTime in general here:http://msdn.microsoft.com/en-us/library/ms973825.aspx. There is also some guidance around using DateTime in interoperable web services here:http://msdn.microsoft.com/en-us/library/ms998265.aspx(the article calls out BEA, but the guidance is applicable to most stacks: DateTime is a value type in .Net and a reference type in many other platforms, so look out for nulls).

Ed
Ed Pinto - MSFT
Hi,
There is some great guidance on working with DateTime in general here:http://msdn.microsoft.com/en-us/library/ms973825.aspx. There is also some guidance around using DateTime in interoperable web services here:http://msdn.microsoft.com/en-us/library/ms998265.aspx(the article calls out BEA, but the guidance is applicable to most stacks: DateTime is a value type in .Net and a reference type in many other platforms, so look out for nulls).

Ed
Ed Pinto - MSFT

You can use google to search for other answers

Custom Search

More Threads

• Error adding web reference: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF
• sessions
• Question about Web Service's Cookie?
• Inheriting from a Web Service Class
• Question regarding Standard SOAP Security Extension
• .NET and VS 2005 compatibility
• Problem with consuming Java web service
• ? retrieving database and writing on the disk ?
• Debugging SoapExtensions
• meta data for web services and UDDI