WCF WebGetAttribute 与 WebInvokeAttribute
WebGetAttribute 只是 Method = "GET" 的 WebInvokeAttribute 的语法糖吗? 或者有根本的区别吗?
Is the WebGetAttribute just syntactic sugar for the WebInvokeAttribute with Method = "GET"?
Or is there an underlying difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您立即观察到 WebGet 和 WebInvoke 非常相似,这与事实相差不远。 正如您已经说过的,WebGet 适用于 HTTP GET 动词,而 WebInvoke 可用于适用于所有其他动词(PUT、POST、DELETE 等)。
WebInvoke 中的许多参数与 WebGet 中的参数相同。 BodyStyle、RequestFormat、ResponseFormat 和 UriTemplate 都适用于 WebGet 和 WebInvoke。 一个区别是 WebInvoke 的“Method”参数的存在。 Method 参数指定与操作相对应的 HTTP 谓词,默认值为 POST。
我还没有机会使用 Reflector 来了解 WebGet 和 WebInvoke 的底层,但我怀疑它们非常相似,尽管它们似乎只是共享 System.Attribute 作为共同的血统。
Your immediate observation that WebGet and WebInvoke are very similar is not all too far from the truth. WebGet, as you've already stated, applies to the HTTP GET verb while WebInvoke can be used to apply to all the other verbs (PUT, POST, DELETE, etc).
Many of the parameters in WebInvoke mirror those in WebGet. BodyStyle, RequestFormat, ResponseFormat, and UriTemplate are all present for both WebGet and WebInvoke. The one differentiator is the presence of the "Method" parameter for WebInvoke. The Method parameter specifies the HTTP verb that corresponds to the operation, with POST being the default value.
I haven't had the chance to use Reflector to look under the hood for WebGet and WebInvoke but I suspect that they are very much alike even though they only seem to share System.Attribute as a common lineage.
好吧,处理请求是有区别的。 通常,使用
WebGet
来表示GET
。 有关详细信息,请参阅我的答案。Well, there is a difference in handling the request. Generally, use
WebGet
forGET
. See my answer for details.