Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Missing Parameters in call to WebService

Missing Parameters in call to WebService

Scheduled Pinned Locked Moved ASP.NET
comhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miszou
    wrote on last edited by
    #1

    I have a trivial webservice set up that takes a single parameter and returns a number of items according to the value of the parameter: [WebMethod( Description="Returns the top 'count' latest articles.")] public XmlDataDocument GetLatestArticles( int count ) { if (count < 1) count = 1; if (count > 100) count = 100; return ArticleCache.GetLatest( count ); } I have some simple parameter checking, such that the method will always return at least one article and at most, 100 articles. However, if the client does not provide the count parameter at all, a System.ArgumentException is thrown before the webmethod is called and an ugly error is returned to the client. I would like to be able to catch this exception and supply a 'default' value to the inner method call, so that the client continues to function. I tried making the count parameter nullable, but then the default WsdlHelpGenerator.aspx doesn't display it, because "The test form is only available for methods with primitive types as parameters." This makes it rather difficult to test - especially as the services are for consumption by a third party developer. Is there any (elegant and easy) way of catching the exception and handling it gracefully? Thanks.

    Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

    S 1 Reply Last reply
    0
    • M Miszou

      I have a trivial webservice set up that takes a single parameter and returns a number of items according to the value of the parameter: [WebMethod( Description="Returns the top 'count' latest articles.")] public XmlDataDocument GetLatestArticles( int count ) { if (count < 1) count = 1; if (count > 100) count = 100; return ArticleCache.GetLatest( count ); } I have some simple parameter checking, such that the method will always return at least one article and at most, 100 articles. However, if the client does not provide the count parameter at all, a System.ArgumentException is thrown before the webmethod is called and an ugly error is returned to the client. I would like to be able to catch this exception and supply a 'default' value to the inner method call, so that the client continues to function. I tried making the count parameter nullable, but then the default WsdlHelpGenerator.aspx doesn't display it, because "The test form is only available for methods with primitive types as parameters." This makes it rather difficult to test - especially as the services are for consumption by a third party developer. Is there any (elegant and easy) way of catching the exception and handling it gracefully? Thanks.

      Sunrise Wallpaper Project | The StartPage Randomizer | The Windows Cheerleader

      S Offline
      S Offline
      SomeGuyThatIsMe
      wrote on last edited by
      #2

      depending on how you have things set up..i wrote an xml file and from there had a wsdl and server stubs generated, but in the XML i'm pretty sure that you can make the parameter optional, then look for it in the server and give it a default value if it s not there. or you might be able to set a default value in the XML...since you typically need a wsdl and the xml file(maybe) to generate a client app, it should work for everyone. i believe setting the minoccurs attribute to 0 in the xml file makes it optional, but i have not tried it.

      Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups