简体   繁体   English

ASP.NET Web服务

[英]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#. ASP.NET WebServices不支持默认参数或方法重载的原因并不是ASP.NET或C#的缺点。 The reason is because WebServices themselves, no matter the language or platform of implementation do not support default parameters or method overloading. 原因是因为WebServices本身,无论实现的语言或平台如何,都不支持默认参数或方法重载。

WebServices are a lowest common denominator technology. WebServices是最低的公分母技术。 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. 您无法保证使用者将使用哪种技术来使用WebService,反之,如果您正在使用WebService,则通常不知道使用什么平台或语言来实现。 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. 不幸的是,即使在.NET 4中C#最终获得了在方法中具有可选参数的功能,但WebMethod仍然不支持它们。 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 :( 我对此也很失望:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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