views:

32

answers:

2

Why doesn't a ASP.NET web method allow default parameters ?

A: 

Unfortunately, even though in .NET 4 C# has finally received the ability to have optional parameters in methods, the WebMethods still do NOT support them. Also, overloading methods doesn't work either. This means you'll have either multiple methods with different names, or the same method with all the parameters, and the optional parameters being nullable.

I was rather disappointed by this as well :(

Artiom Chilaru
+1  A: 

The reason ASP.NET WebServices don't support default parameters or method overloading is not a shortcoming of ASP.NET or C#. The reason is because WebServices themselves, no matter the language or platform of implementation do not support default parameters or method overloading.

WebServices are a lowest common denominator technology. You cannot guarantee what technology the consumer will use to consume your WebService, and conversely, if you're consuming a WebService, you often have no idea what platform or language it was implemented with. Because of this we have to use a feature-set that we're pretty sure any platform will be able to work with.

Greg B