views:

619

answers:

2

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.

+3  A: 

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

John Saunders
I see the error of my ways now. My webclient can call either UploadFile or UploadFileBasic. My webservice defines both uniquely now (no overloading). More significantly, thanks to another suggestion elsewhere, the code for UploadFileBasic is now simply the invocation of UploadFile supplying an empty array as the last parameter. Thank you for all your help, John.
John Galt
A: 

I would generally have a class object behind the web service interface that has the overloaded methods and then create individual methods in your asmx.cs file with different names. I know you can use the attributes but it just makes tidier code IMHO.

Keith