为什么 ASP.NET Web 方法不允许使用默认参数?
2 回答
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.
不幸的是,即使在 .NET 4 C# 中终于获得了在方法中具有可选参数的能力,WebMethods 仍然不支持它们。此外,重载方法也不起作用。这意味着您将拥有多个具有不同名称的方法,或者具有所有参数的相同方法,并且可选参数可以为空。
我也对此感到相当失望:(