I've never used C# nor have I created Web Services, so I am in the process
of finding tutorials on the web and going through them. I found this one
over at code project:
http://www.thecodeproject.com/cs/webservices/myservice.asp I am presented with this method:
[WebMethod]
public ClientData[] GetClientData(int Number)
{
ClientData [] Clients = null;
if (Number > 0 && Number <= 10)
{
Clients = new ClientData[Number];
for (int i = 0; i < Number; i++)
{
Clients[i].Name = "Client " + i.ToString();
Clients[i].ID = i;
}
}
return Clients;
}
Anyhow, on the web page for GetClientData, I decide not to type in a value
for the Number field and I click the 'Invoke' button. I receive this:
System.ArgumentException: Cannot convert 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(IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType,
IFormatProvider provider)
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(NameValueC
ollection collection)
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest
request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
Question #1:
What can I use to determine if a user has passed a parameter correctly? Or
even at all? Is the value null - since I didn't put in a value? But how wo
uld you compare an int to null!?
Question #2:
Is it possible to have default parameters (so it would default to a certain
value)?
Question #3:
How do I DEBUG a Web Service? I set a breakpoint so I could try to figure
out what the Number value was - I pressed F5, it launched a browser, I
clicked the Invoke button - it didn't reach my breakpoint.
Yep. As you can see, I am really brand-y-newbie here.
Thanks!