WCF WebGetAttribute vs WebInvokeAttribute

人盡茶涼 提交于 2019-12-05 19:21:19

问题


Is the WebGetAttribute just syntactic sugar for the WebInvokeAttribute with Method = "GET"? Or is there an underlying difference?


回答1:


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.




回答2:


Well, there is a difference in handling the request. Generally, use WebGet for GET. See my answer for details.



来源:https://stackoverflow.com/questions/1072556/wcf-webgetattribute-vs-webinvokeattribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!