By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,492 Members | 1,289 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,492 IT Pros & Developers. It's quick & easy.

Error converting DateTime in WebService Method parameter

P: n/a
Hi,

I have a web service method which takes a DateTime type as a parameter.
The service is UK based, and the dates are passed in to the service in the
UK format dd/MM/yyyy.

On a recent install, the web service method will not accept the UK date
format, erroring with a System.Argument exception, but would take US
formatted dates.

As the DateTime type is a method parameter, I cannot use an IFormatProvider
to Parse the date, and check for any errors. What appears to be happening is
that the Web Service code which runs before my method code runs is trying to
Parse the date, but why would it choose US date?

All locale settings on the machine are English (United Kingdom). I have
checked all the the registry entries under HKU -S....... -Control Panel
-International, and they are all set to English (United Kingdom). I have
also set the globalization element in the web.config file for both the
CurrentCulture and CurrentUICulture to en-GB.

So this appears to be the .NET framework code, perhaps as a result of the
[WebMethod] attribute, deserializing the date, and attempting to create a
DateTime object on behalf of the method, but why is it choosing the en-US
method??

Stack Trace

System.ArgumentException: Cannot convert 31/03/2006 to System.DateTime.
Parameter name: type ---System.FormatException: String was not recognized
as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDateTime(IForm atProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
at
System.Web.Services.Protocols.ValueCollectionParam eterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.HtmlFormParameterRea der.Read(HttpRequest
request)
at System.Web.Services.Protoco

Any help would be greatly appreciated.

Rich
Jul 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Rich,

Did you check the culture infor for the current thread ?.

System.Globalization.CultureInfo ci =
System.Threading.Thread.CurrentThread.CurrentCultu re;

If that CultureInfo instance is US, some globalization setting is not being
applied correctly in your application.

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
[MVP - Connected Systems Developer]

"Rich Robinson" <Rich Ro******@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Hi,

I have a web service method which takes a DateTime type as a parameter.
The service is UK based, and the dates are passed in to the service in the
UK format dd/MM/yyyy.

On a recent install, the web service method will not accept the UK date
format, erroring with a System.Argument exception, but would take US
formatted dates.

As the DateTime type is a method parameter, I cannot use an
IFormatProvider
to Parse the date, and check for any errors. What appears to be happening
is
that the Web Service code which runs before my method code runs is trying
to
Parse the date, but why would it choose US date?

All locale settings on the machine are English (United Kingdom). I have
checked all the the registry entries under HKU -S....... -Control
Panel
-International, and they are all set to English (United Kingdom). I have
also set the globalization element in the web.config file for both the
CurrentCulture and CurrentUICulture to en-GB.

So this appears to be the .NET framework code, perhaps as a result of the
[WebMethod] attribute, deserializing the date, and attempting to create a
DateTime object on behalf of the method, but why is it choosing the en-US
method??

Stack Trace

System.ArgumentException: Cannot convert 31/03/2006 to System.DateTime.
Parameter name: type ---System.FormatException: String was not
recognized
as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDateTime(IForm atProvider
provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Web.Services.Protocols.ScalarFormatter.From String(String
value,
Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.From String(String
value,
Type type)
at
System.Web.Services.Protocols.ValueCollectionParam eterReader.Read(NameValueCollection
collection)
at
System.Web.Services.Protocols.HtmlFormParameterRea der.Read(HttpRequest
request)
at System.Web.Services.Protoco

Any help would be greatly appreciated.

Rich

Jul 17 '06 #2

P: n/a
Hi,

I have a web service method which takes a DateTime type as a parameter.
The service is UK based, and the dates are passed in to the service in the
UK format dd/MM/yyyy.

On a recent install, the web service method will not accept the UK date
format, erroring with a System.Argument exception, but would take US
formatted dates.

As the DateTime type is a method parameter, I cannot use an IFormatProvider
to Parse the date, and check for any errors. What appears to be happening is
that the Web Service code which runs before my method code runs is trying to
Parse the date, but why would it choose US date?

All locale settings on the machine are English (United Kingdom). I have
checked all the the registry entries under HKU -S....... -Control Panel
-International, and they are all set to English (United Kingdom). I have
also set the globalization element in the web.config file for both the
CurrentCulture and CurrentUICulture to en-GB.

So this appears to be the .NET framework code, perhaps as a result of the
[WebMethod] attribute, deserializing the date, and attempting to create a
DateTime object on behalf of the method, but why is it choosing the en-US
method??

Stack Trace

System.ArgumentException: Cannot convert 31/03/2006 to System.DateTime.
Parameter name: type ---System.FormatException: String was not recognized
as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDateTime(IForm atProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
at
System.Web.Services.Protocols.ValueCollectionParam eterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.HtmlFormParameterRea der.Read(HttpRequest
request)
at System.Web.Services.Protoco

Any help would be greatly appreciated.

Rich
I have the samo error in my multilanguage aplication.
i got this error when i receave data like this 10.23.2006 or 10/23/2006 so i did something simple.Just change the place of Month and Day (from 10.23.2006 to 23.10.2006) and i have no more this problem :P

Posted from http://www.topxml.com/renntp using reNNTP: the website based NNTP reader.
Aug 10 '06 #3

P: n/a
Is the client computer configured for US English?

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Rich Robinson" wrote:
Hi,

I have a web service method which takes a DateTime type as a parameter.
The service is UK based, and the dates are passed in to the service in the
UK format dd/MM/yyyy.

On a recent install, the web service method will not accept the UK date
format, erroring with a System.Argument exception, but would take US
formatted dates.

As the DateTime type is a method parameter, I cannot use an IFormatProvider
to Parse the date, and check for any errors. What appears to be happening is
that the Web Service code which runs before my method code runs is trying to
Parse the date, but why would it choose US date?

All locale settings on the machine are English (United Kingdom). I have
checked all the the registry entries under HKU -S....... -Control Panel
-International, and they are all set to English (United Kingdom). I have
also set the globalization element in the web.config file for both the
CurrentCulture and CurrentUICulture to en-GB.

So this appears to be the .NET framework code, perhaps as a result of the
[WebMethod] attribute, deserializing the date, and attempting to create a
DateTime object on behalf of the method, but why is it choosing the en-US
method??

Stack Trace

System.ArgumentException: Cannot convert 31/03/2006 to System.DateTime.
Parameter name: type ---System.FormatException: String was not recognized
as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi,
DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value, IFormatProvider provider)
at System.String.System.IConvertible.ToDateTime(IForm atProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.From String(String value,
Type type)
at
System.Web.Services.Protocols.ValueCollectionParam eterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.HtmlFormParameterRea der.Read(HttpRequest
request)
at System.Web.Services.Protoco

Any help would be greatly appreciated.

Rich
Sep 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.