Search code examples
c#web-servicesasmx

How to access a web service with overloaded methods


I'm trying to have overloaded methods in a web service but I am getting a System.InvalidOperationException when attempting "Add Web Reference" in Visual Studio 2005 (here's the relevant snippets of code):

public class FileService : System.Web.Services.WebService
{
    private static readonly MetaData[] EmptyMetaData = new MetaData[0];
    public FileService()
    {
    // a few innocent lines of constructor code here...
    }
    [WebMethod(MessageName = "UploadFileBasic", 
        Description = "Upload a file with no metadata properties")]
    public string UploadFile(string trimURL
        , byte[] incomingArray
        , string fileName
        , string TrimRecordTypeName)
    {
        return UploadFile(trimURL
                , incomingArray
                , fileName
                , TrimRecordTypeName
                , EmptyMetaData);
    }
    [WebMethod(MessageName = "UploadFile",
        Description = "Upload a file with an array of metadata properties (Name/Value pairs)")]
    public string UploadFile( string trimURL
        , byte[] incomingArray
        , string FileName
        , string TrimRecordTypeName
        , MetaData[] metaDataArray)
    {
    // body of UploadFile function here 

I thought supplying a different MessageName property on the WebMethod attribute would fix this problem but here is the entire error message I get:

Both System.String UploadFileBasic(System.String, Byte[], System.String, System.String) and System.String UploadFile(System.String, Byte[], System.String, System.String) use the message name 'UploadFileBasic'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.

The web service compiles OK; I cannot see what is wrong here.


Solution

  • My suggestion is to not use overloaded method names. There is no such concept in WSDL, so why bother?