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

Protocols.ScalarFormatter

P: n/a
Hi, All,
I have a web method like this:

[WebMethod]
public string test(int32 i)
{
return i.ToString();
}

and If I pass an empty string to test it by using HTTP POST I got the
following error:

System.ArgumentException: Cannot convert Test to System.Int32.
Parameter name: type ---> System.FormatException: Input string was not in a
correct format.
at System.Number.ParseInt32(String s, NumberStyles style,
NumberFormatInfo info)
at System.String.System.IConvertible.ToInt32(IFormatP rovider 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(NameValueC
ollection collection)
at System.Web.Services.Protocols.UrlParameterReader.R ead(HttpRequest
request)
at System.Web.Services.Protocols.HttpServerProtocol.R eadParameters()
at System.Web.Services.Protocols.WebServiceHandler.In voke()
at System.Web.Services.Protocols.WebServiceHandler.Co reProcessRequest()

This is due to the WebServices framework tries to parse the empty string
into integer which it will be a problem. I tried to use SoapExtension to
modify the SoapMessage before it's deserialized but unfortunately this event
in ProcessMessage happens after the above parameter conversion. Is there
anyway to override this behavior?

I want change the parameter to 0 if it's empty string - where can I do it? I
know we can implement a HTTP handler to get the stream and modify from there
but that's too low level.

Hope MSFT provide an attribute you can apply for that :)

Thanks a lot!

Nov 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.