WCF WebGetAttribute 与 WebInvokeAttribute

发布于 2024-07-25 18:48:55 字数 80 浏览 1 评论 0原文

WebGetAttribute 只是 Method = "GET" 的 WebInvokeAttribute 的语法糖吗? 或者有根本的区别吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没有 2024-08-01 18:48:55

您立即观察到 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.

绿萝 2024-08-01 18:48:55

好吧,处理请求是有区别的。 通常,使用 WebGet 来表示 GET。 有关详细信息,请参阅我的答案

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文