tags:

views:

50

answers:

1

Hello, I have a WCF service that requires some DateTime parameters to be passed in. The service will be used globally and be consumed by different clients (.NET, PHP etc). What is the best format to get the datetime parameters in? I was thinking of making them string parameters, and then advising the users of the format needed.

Maybe something like "yyyy-MM-ddTHH:mm:ss"

Then in the service I could do something like this;

DateTime usedatetime = DateTime.ParseExact(PassedDate, "yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture);

I did try this, it worked fine on my local pc, but failed on the deployment server..."String was not recognized as a valid DateTime."

I guess my question is; What is the best way to handle date parameters in WCF? I really hope that makes sense...

+1  A: 

It may be a problem with the string PassedDate, what is in that variable?

Shiraz Bhaiji
It is "2010-10-29T10:12:12"
rickj
Sorry, found the cause of the error, was a point in code that I had not converted correctly...
rickj
So back to my overriding question. Is using string type for the datetime parameters the accepted/preferred way to handle passing datetime parameters?
rickj
It depends, but as a string with a documented format, is a robust way to send a date between systems with various technologies and configurations.
Shiraz Bhaiji
Thanks Shiraz. I have decided to go with the string parameters and all seems fine. Thanks for the comments.
rickj