为什么静态方法不能用作Web服务操作在ASMX Web服务? [英] Why are Static Methods not Usable as Web Service Operations in ASMX Web Services?

查看:174
本文介绍了为什么静态方法不能用作Web服务操作在ASMX Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想了解为什么我不能静态Web方法Web服务?为什么限制?

I just wanna learn why I can't static web methods in web services ? Why is it restricted ?

可一些身体给我的这个简明的解释。

Can some body give me concise explanation of this.

推荐答案

答案是:因为你不能

这不是这样设计的。该设计是Web服务类的实例将被创建,然后一个实例方法将被调用。

It's not designed that way. The design is that an instance of the web service class will be created, and then an instance method will be called.

我只能猜测为何微软设计的这种方式。要肯定知道,你得问他们。试想一下:

I can only guess why Microsoft designed it that way. To know for sure, you'd have to ask them. Consider:


  1. 有来允许静态方法没有特别的好处。任何你可以用一个静态方法做,你也可以做一个实例方法。

  2. A [WebService的] 类并不意味着是碰巧被用作Web服务一些任意类。它的意思是,你暴露Web服务操作的目的而创建的类。因此,没有必要支持已经存在的类和已具备的静态方法。

  3. SOAP头实现允许你的类包含一个类型从 SOAPHEADER 类派生的一个实例字段。此字段将充满传入SOAP头和/或将包含SOAP头被返回。你不能用静态场做到这一点,因为这将与每个请求所覆盖。

  1. There's no particular benefit to permitting static methods. Anything you can do with a static method, you can also do with an instance method.
  2. A [WebService] class is not meant to be some arbitrary class that happens to be used as a web service. It's meant to be a class that you created for the purpose of exposing web service operations. As such, there is no need to support classes that already exist and already have static methods.
  3. The SOAP Header implementation permits your class to contain an instance field of a type deriving from the SoapHeader class. This field will be filled with an incoming SOAP header and/or will contain the SOAP Header to be returned. You could not do this with a static field, as it would be overwritten with each request.

正如我所说的,这些都是猜测。正确答案的问题是,你不能因为这是微软如何设计它。如果你想知道为什么他们设计了这样的说法,你需要问他们。

As I said, these are all guesses. The correct answer to the question is, "you can't because that's how Microsoft designed it. If you want to know why they designed it that way, you need to ask them".


FWIW,我只是检查,并不会出现WCF允许静态方法要操作要么。

FWIW, I just checked, and it does not appear that WCF permits static methods to be operations either.

这篇关于为什么静态方法不能用作Web服务操作在ASMX Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆