today’s c# lesson

I don’t code in c# everyday, so that’s my excuse for forgetting that c# does not support assigning default values to method arguments. That’s by design according to a Microsoft tech. Well OK, I write another method with the same name but no arguments (creating a different signature) — that’s legit in c# — and in it’s body call the original method passing in my default values. A workaround that’s a bit silly but not too painful.

Until I try to call this method from a client app. Did I mention it was in a web service? Apparently [WebMethod]s do not support methods with different signatures. They compile and build with no errors and you can publish them on your IIS server but when you try to add them as a web reference to your vStudio client app they throw runtime errors. Yo, what kind of coding environment is this? They’re not making it easy here. Oh well, another day another challenge.

3 Responses to “today’s c# lesson”

  1. Josh Says:

    Frank,

    My webmethods aren’t causing problems as webreferences and they use different signatures.. these aren’t instantiators though, is that the difference?

    [WebMethod(Description=”Upload a file to a fileshare, specifying the server path, directory, identifier, and filename”, MessageName=”UploadToSpecificServer”)]

    public void UploadFile(string path, string directoryName, string identifier, string filename) {

    [WebMethod(Description=”Upload a file to a fileshare, specifying the directory, identifier, and filename”, MessageName=”UploadToDefaultServer”)]

    public void UploadFile(string directoryName, string identifier, string filename) {

  2. frog Says:

    Interesting Josh. Of my two webmethods one takes an int and the other takes no args and as mentioned in my post I got a runtime error trying to add the web reference to my client app. Problem disappeared when I commented out one of the webmethods. I’ll have to research this further, since you give me hope that there may be a way to get it to work. FYI: the web service is built in vstudio 2003 and the client in vstudio 2008.

  3. Josh Says:

    I wonder if vstudio 2008 is doing something here, my service and clients are all vstudio 2003… I’d definitely be keen on knowing if you find out that its vstudio 2008!

Leave a Reply