Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / September 2004

Tip: Looking for answers? Try searching our database.

3 newbie/C#/WebServices questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William Campbell - 27 Sep 2004 23:29 GMT
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!
Sami Vaaraniemi - 28 Sep 2004 20:50 GMT
Comments inline:

> 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
[quoted text clipped - 38 lines]
> 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()
[quoted text clipped - 5 lines]
> 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!?

Yes, if you do not provide a value for the int parameter in the web page,
then the call fails already before your code in the web method gets a chance
to execute. If you want to allow passing nulls then one way to do this is to
wrap the int into a simple class and use it as the parameter to the web
method

public class NullableInt
{
   public int Value;
}

[WebMethod()]
public void ThisMethodAllowsNullArgument(NullableInt nullableInt)
{
   if (nullableInt == null) ...
}

Note that if you use this class then you can't invoke the web method through
the browser any more because the browser form only works with primitive
types.

> Question #2:
> Is it possible to have default parameters (so it would default to a certain
> value)?

ASP.NET Web Services have no support for default values out of the box. For
more flexibility, you could pass e.g., an XML document as a parameter
instead of an int, and implement any default value logic in application
code.

> 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.

Debugging works as you would expect except in this case the exception occurs
before execution reaches your breakpoint.

Regards,
Sami

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.