简体   繁体   中英

ASP.NET Web Service

为什么ASP.NET Web方法不允许默认参数?

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.

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 :(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM