Web Service Overloads?

I just discovered overloads for webmethods cannot have the same name.  Don't other platforms have the concept of differing method signatures with the same name?

Here's the fix to change the name of one or both methods via an alias:

[WebMethod(MessageName="MethodAlias")]
public ReturnType MethodName(string param1)
{
    return MethodName(param1,"HardParam2");
}

[WebMethod(MessageName="MethodAliasPlain")]
public ReturnType MethodName(string param1, string param2)
{
   //actual service code here.
}

7 Comments

  • Hi Jason,



    No many languages do not have this concept. Eiffel for one...I am sure many others.



    This was also an issue for Microsoft when designing the CLS (Common Language Subset for .NET), because they needed to decide if method overloading would be part of the CLS. In the end they decided it *would* be part of the CLS, even though the designers of many other laugnaged (like Eiffel) objected.



    Note that for the CLS...All languages need to "fudge/simulate" this feature...Even if they do not have it.

  • Two reasons.



    First, Web Services are about interoperability, and not all languages may have this possibility. Most hae overloads, but some do not.



    Second, imho more important, is that the XML form of this may make it hard to actually figure out which overload to use.

  • Simple and interesting solution .

  • Web Services are *NOT* about XML-pregnant OO and RPC... please: everybody respect this now and forever ;)

    You *MUST* not care about this 'problem'. I am sorry...

    Think in messages, think in services. Nuff said.

  • ...note: the property is named 'MessageName'.

  • Christian... MessageName is in fact what is in the sample code... MethodName is just an arbitrary holder for whatever your OO overloads are...



    And as far as asking us to respect it, we're not given the choice :)



    I don't really mind so much, it's just a shift in mindset, and a good thing to keep in mind when developing web services only casually (as in my case).

  • I think my 'message' didn't get through :)

    Web Services are not about OO. Not about objects. Not about overloading... et.al.

    That's all I wanted to say.



    If you want to embrace this idea, lemme know.



    Cheers.

Comments have been disabled for this content.