Can web methods be overloaded ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john bailo

    #1

    Can web methods be overloaded ?


    Can a web method be overloaded?

    To support varying numbers of input parameters?



  • Greg Ewing [MVP]

    #2
    Re: Can web methods be overloaded ?

    john, yes you can but you need to specify the MessageName attribute though
    as an alias for the WSDL. Here's an example.

    <%@ WebService Language="C#" Class="Calculat or" %>

    using System;
    using System.Web.Serv ices;

    public class Calculator : WebService {
    // The MessageName property defaults to Add for this XML Web service
    method.
    [WebMethod]
    public int Add(int i, int j) {
    return i + j;
    }
    [WebMethod(Messa geName="Add2")]
    public int Add(int i, int j, int k) {
    return i + j + k;
    }
    }

    --
    Greg Ewing [MVP]
    IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.



    "john bailo" <jbailo@vestcom .com> wrote in message
    news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=blue]
    >
    > Can a web method be overloaded?
    >
    > To support varying numbers of input parameters?
    >
    >
    >[/color]


    Comment

    • Chris Taylor

      #3
      Re: Can web methods be overloaded ?

      Hi,

      No Web Service methods can not be overloaded. If you want to expose an
      overloaded class method, you will have to provide a alias using the
      MessageName property of the WebMethodAttrib ute.

      C# : [WebMethod( MessageName="Ge tCustomerByID" )]

      VB.NET <WebMethod( MessageName := "GetCustomerByI D)>

      Hope this helps

      Chris Taylor

      "john bailo" <jbailo@vestcom .com> wrote in message
      news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=blue]
      >
      > Can a web method be overloaded?
      >
      > To support varying numbers of input parameters?
      >
      >
      >[/color]


      Comment

      • john bailo

        #4
        Re: Can web methods be overloaded ?

        if I want to use 3 parameters,

        when I call the method from a client,

        do I use Add or Add2 as my method?

        Or is an 'alias' just a 'cosmetic' name for the overloaded
        Add function?

        "Greg Ewing [MVP]" <gewing@_NO_SPA M_gewing.com> wrote in message
        news:%230EXMzqk DHA.3504@TK2MSF TNGP11.phx.gbl. ..[color=blue]
        > john, yes you can but you need to specify the MessageName attribute though
        > as an alias for the WSDL. Here's an example.
        >
        > <%@ WebService Language="C#" Class="Calculat or" %>
        >
        > using System;
        > using System.Web.Serv ices;
        >
        > public class Calculator : WebService {
        > // The MessageName property defaults to Add for this XML Web service
        > method.
        > [WebMethod]
        > public int Add(int i, int j) {
        > return i + j;
        > }
        > [WebMethod(Messa geName="Add2")]
        > public int Add(int i, int j, int k) {
        > return i + j + k;
        > }
        > }
        >
        > --
        > Greg Ewing [MVP]
        > http://www.citidc.com
        >
        >
        > "john bailo" <jbailo@vestcom .com> wrote in message
        > news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=green]
        > >
        > > Can a web method be overloaded?
        > >
        > > To support varying numbers of input parameters?
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Greg Ewing [MVP]

          #5
          Re: Can web methods be overloaded ?

          john, the client will have to use Add2.

          --
          Greg Ewing [MVP]
          IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


          "john bailo" <jbailo@vestcom .com> wrote in message
          news:f7a5f8a3b7 5ce6503ea694137 0e983f6@news.te ranews.com...[color=blue]
          > if I want to use 3 parameters,
          >
          > when I call the method from a client,
          >
          > do I use Add or Add2 as my method?
          >
          > Or is an 'alias' just a 'cosmetic' name for the overloaded
          > Add function?
          >
          > "Greg Ewing [MVP]" <gewing@_NO_SPA M_gewing.com> wrote in message
          > news:%230EXMzqk DHA.3504@TK2MSF TNGP11.phx.gbl. ..[color=green]
          > > john, yes you can but you need to specify the MessageName attribute[/color][/color]
          though[color=blue][color=green]
          > > as an alias for the WSDL. Here's an example.
          > >
          > > <%@ WebService Language="C#" Class="Calculat or" %>
          > >
          > > using System;
          > > using System.Web.Serv ices;
          > >
          > > public class Calculator : WebService {
          > > // The MessageName property defaults to Add for this XML Web service
          > > method.
          > > [WebMethod]
          > > public int Add(int i, int j) {
          > > return i + j;
          > > }
          > > [WebMethod(Messa geName="Add2")]
          > > public int Add(int i, int j, int k) {
          > > return i + j + k;
          > > }
          > > }
          > >
          > > --
          > > Greg Ewing [MVP]
          > > http://www.citidc.com
          > >
          > >
          > > "john bailo" <jbailo@vestcom .com> wrote in message
          > > news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=darkred]
          > > >
          > > > Can a web method be overloaded?
          > > >
          > > > To support varying numbers of input parameters?
          > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Burgess Meredith

            #6
            Re: Can web methods be overloaded ?

            Greg Ewing [MVP] dribbled:
            [color=blue]
            > john, the client will have to use Add2.[/color]

            Is that 'overloaded' then?

            Isn't that just the same as two methods?



            Comment

            • Burgess Meredith

              #7
              Re: Can web methods be overloaded ?

              Chris Taylor dribbled:
              [color=blue]
              > Hi,
              >
              > No Web Service methods can not be overloaded. If you want to expose an[/color]

              ok, so the benefits of overloading
              are lost when calling a web method.

              to me, that's a shame, because the ability
              to send varying numbers of parameters and
              parameter types to the same method would be
              really valuable for a remote client, talking
              to a web method.

              if you think http post, there may be several
              uses of the same function but with different
              UI's that would want to use the method.


              Comment

              • Greg Ewing [MVP]

                #8
                Re: Can web methods be overloaded ?

                Burgess, in terms of the server code, yes, it's overloading. In terms of
                the client, no, it's not. Unfortunately that's a limitation of WSDL.

                http://www.w3.org/TR/wsdl

                --
                Greg Ewing [MVP]
                IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.



                "Burgess Meredith" <jabailo@earthl ink.net> wrote in message
                news:4a5e602a3e 4031a9d08092d66 3967edb@news.te ranews.com...[color=blue]
                > Greg Ewing [MVP] dribbled:
                >[color=green]
                > > john, the client will have to use Add2.[/color]
                >
                > Is that 'overloaded' then?
                >
                > Isn't that just the same as two methods?
                >
                >
                >[/color]


                Comment

                • Girish Bharadwaj

                  #9
                  Re: Can web methods be overloaded ?

                  Burgess Meredith wrote:
                  [color=blue]
                  > Chris Taylor dribbled:
                  >
                  >[color=green]
                  >>Hi,
                  >>
                  >>No Web Service methods can not be overloaded. If you want to expose an[/color]
                  >
                  >
                  > ok, so the benefits of overloading
                  > are lost when calling a web method.
                  >
                  > to me, that's a shame, because the ability
                  > to send varying numbers of parameters and
                  > parameter types to the same method would be
                  > really valuable for a remote client, talking
                  > to a web method.
                  >
                  > if you think http post, there may be several
                  > uses of the same function but with different
                  > UI's that would want to use the method.
                  >
                  >[/color]
                  You can easily handle this by making the web method accept a XMLDocument
                  as input rather than explicit parameters. They you would have control
                  over the kind of stuff you can get into that web method and you would
                  need to overload methods.

                  Of course, this would mean that you now have to write code to
                  de-serialize XML document to a real object. But that is a *good* thing.


                  --
                  Girish Bharadwaj

                  Comment

                  • Bubba Thomas

                    #10
                    Re: Can web methods be overloaded ?

                    Chris,

                    I tried your VB.NET version but it does not work. Firstly, I think you
                    forgot the closing " after GetCustomerByID but I get the following error !


                    Attribute "WebMethodAttri bute" cannot be applied to '.ctor' because the
                    attribute is not valid on this attribute type.


                    Any ideas ?


                    ThanX !

                    Bubba !



                    "Chris Taylor" <chris_taylor_z a@hotmail.com> wrote in message
                    news:evB9o4qkDH A.2080@TK2MSFTN GP10.phx.gbl...[color=blue]
                    > Hi,
                    >
                    > No Web Service methods can not be overloaded. If you want to expose an
                    > overloaded class method, you will have to provide a alias using the
                    > MessageName property of the WebMethodAttrib ute.
                    >
                    > C# : [WebMethod( MessageName="Ge tCustomerByID" )]
                    >
                    > VB.NET <WebMethod( MessageName := "GetCustomerByI D)>
                    >
                    > Hope this helps
                    >
                    > Chris Taylor
                    >
                    > "john bailo" <jbailo@vestcom .com> wrote in message
                    > news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=green]
                    > >
                    > > Can a web method be overloaded?
                    > >
                    > > To support varying numbers of input parameters?
                    > >
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Jim Blizzard [MSFT]

                      #11
                      Re: Can web methods be overloaded ?

                      Hi Bubba,

                      Thanks for posting to the newsgroup.

                      From the error message, it appears as though you're trying to create an
                      "overloaded " constructor for your web method. Is this really what you want
                      to do?

                      - bliz
                      --
                      Jim Blizzard, MCSD .NET
                      Community Developer Evangelist | http://www.microsoft.com/communities
                      Microsoft

                      Your Potential. Our Passion.

                      This posting is provided as is, without warranty, and confers no rights.

                      "Bubba Thomas" <bubba@ILU.co m> wrote in message
                      news:ulNtCv3sDH A.3140@TK2MSFTN GP11.phx.gbl...[color=blue]
                      > Chris,
                      >
                      > I tried your VB.NET version but it does not work. Firstly, I think[/color]
                      you[color=blue]
                      > forgot the closing " after GetCustomerByID but I get the following error !
                      >
                      >
                      > Attribute "WebMethodAttri bute" cannot be applied to '.ctor' because the
                      > attribute is not valid on this attribute type.
                      >
                      >
                      > Any ideas ?
                      >
                      >
                      > ThanX !
                      >
                      > Bubba !
                      >
                      >
                      >
                      > "Chris Taylor" <chris_taylor_z a@hotmail.com> wrote in message
                      > news:evB9o4qkDH A.2080@TK2MSFTN GP10.phx.gbl...[color=green]
                      > > Hi,
                      > >
                      > > No Web Service methods can not be overloaded. If you want to expose an
                      > > overloaded class method, you will have to provide a alias using the
                      > > MessageName property of the WebMethodAttrib ute.
                      > >
                      > > C# : [WebMethod( MessageName="Ge tCustomerByID" )]
                      > >
                      > > VB.NET <WebMethod( MessageName := "GetCustomerByI D)>
                      > >
                      > > Hope this helps
                      > >
                      > > Chris Taylor
                      > >
                      > > "john bailo" <jbailo@vestcom .com> wrote in message
                      > > news:d6f4ae9383 04a93af0d7bec27 31ddcc3@news.te ranews.com...[color=darkred]
                      > > >
                      > > > Can a web method be overloaded?
                      > > >
                      > > > To support varying numbers of input parameters?
                      > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      Working...