123qweasdzc
Programmer
I have a simple "helloWorld" webService:
using System;
using System.Web;
using System.Web.Services;
namespace WebServiceTest
{
public class WebServiceTest : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(byte number)
{
return "Hello World" + number;
}
}
}
How and where can I validate if the "number" is actually a byte type? If I write the number 256 the exception is raise:
System.ArgumentException: Cannot convert 256 to System.Byte.
Parameter name: type ---> System.OverflowException: Value was either too large or too small for an unsigned byte.
at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.String.System.IConvertible.ToByte(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
using System;
using System.Web;
using System.Web.Services;
namespace WebServiceTest
{
public class WebServiceTest : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(byte number)
{
return "Hello World" + number;
}
}
}
How and where can I validate if the "number" is actually a byte type? If I write the number 256 the exception is raise:
System.ArgumentException: Cannot convert 256 to System.Byte.
Parameter name: type ---> System.OverflowException: Value was either too large or too small for an unsigned byte.
at System.Byte.Parse(String s, NumberStyles style, IFormatProvider provider)
at System.String.System.IConvertible.ToByte(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type)
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()