Optional parameter in a web service?

Discussion in 'ASP .Net Web Services' started by UJ, Dec 27, 2005.

  1. UJ

    UJ Guest

    Is there a way to make a parameter optional in a web server? I've got two
    routines that will work almost exactly the same except that one needs an
    extra parameter to do a check. I supposed I could something like:


    public int WithOneParm ( int parm1 )
    {
    }

    public int WithTwoParm (int parm1, int parm2 )
    {
    // Do what is needed for this.
    WithOneParm ( parm1 );
    }


    but I'd love to be able to have just the one routine.

    TIA - Jeff.
    UJ, Dec 27, 2005
    #1
    1. Advertising

  2. UJ

    Martin Kulov Guest

    "UJ" <> wrote in message
    news:...
    > Is there a way to make a parameter optional in a web server?


    Hi Jeff,

    AFAIK, you can not create optional parameters in web services.
    That's a design restriction, at least for now.
    However you van overload the method and create versions of the method with
    one and two parameters.

    Happy holidays,

    --
    Martin Kulov
    http://www.codeattest.com/blogs/martin

    MCAD Charter Member
    MCSD.NET Early Achiever
    MCSD
    Martin Kulov, Dec 28, 2005
    #2
    1. Advertising

  3. UJ

    BobG Guest

    You could do this with a dataset that has 2 tables. Each table has one column
    and one row. Place the required parameter in one table and the optional
    parameter in the other.

    Note with this approach the datatypes of the parameters can be different and
    it's not a problem.

    Good luck with your work!

    "UJ" wrote:

    > Is there a way to make a parameter optional in a web server? I've got two
    > routines that will work almost exactly the same except that one needs an
    > extra parameter to do a check. I supposed I could something like:
    >
    >
    > public int WithOneParm ( int parm1 )
    > {
    > }
    >
    > public int WithTwoParm (int parm1, int parm2 )
    > {
    > // Do what is needed for this.
    > WithOneParm ( parm1 );
    > }
    >
    >
    > but I'd love to be able to have just the one routine.
    >
    > TIA - Jeff.
    >
    >
    >
    BobG, Dec 30, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    6
    Views:
    69,834
    grizzleybear
    Apr 17, 2012
  2. Otto Wyss
    Replies:
    6
    Views:
    431
    Jeff Flinn
    Nov 9, 2004
  3. Replies:
    2
    Views:
    268
    Bruno Desthuilliers
    Oct 30, 2006
  4. John Harkin
    Replies:
    0
    Views:
    192
    John Harkin
    Apr 13, 2004
  5. Sinex

    Usage of Use="Optional" on a web method parameter...

    Sinex, May 1, 2007, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    155
    Sinex
    May 1, 2007
Loading...

Share This Page