简体   繁体   English

WebGet在功能上等同于WebInvoke(Method =“GET”)吗?

[英]Is WebGet functionally equivalent to WebInvoke(Method = “GET”)?

This question already asks what I'm asking, but I want some clarification on the answer. 这个问题已经问到我在问什么,但我想要澄清答案。

The answer states that WebGet and WebInvoke are similar, and that the primary difference is the Method parameter. 答案表明WebGetWebInvoke类似,主要区别在于Method参数。

But if the Method parameter is set to "GET" , is it actually functionally equivalent, or are there other differences? 但是,如果Method参数设置为"GET" ,它实际上是功能相同的,还是存在其他差异?

They are simply marker attributes and end up being 100% functionally equivalent. 它们只是标记属性,最终在功能上等同于100%。 The only thing that interprets these attributes is the WebHttpBehavior::GetWebMethod method and its functionality is simply: 解释这些属性的唯一因素是WebHttpBehavior::GetWebMethod方法,其功能很简单:

internal static string GetWebMethod(OperationDescription od)
{
    WebGetAttribute webGetAttribute = od.Behaviors.Find<WebGetAttribute>();
    WebInvokeAttribute webInvokeAttribute = od.Behaviors.Find<WebInvokeAttribute>();
    WebHttpBehavior.EnsureOk(webGetAttribute, webInvokeAttribute, od);
    if (webGetAttribute != null)
    {
        return "GET";
    }
    if (webInvokeAttribute == null)
    {
        return "POST";
    }
    return webInvokeAttribute.Method ?? "POST";
}

It is not. 它不是。

I just spent few hours trying to replace WCF DataContractJsonSerializer with Newtonsoft JsonSerializer using MessageFormatter based on this and this samples 我花了几个小时尝试使用MessageFormatter基于示例使用Newtonsoft JsonSerializer替换WCF DataContractJsonSerializer

found out (the hard way) there IS difference in using WebGet and WebInvoke(Method="GET") . 发现(困难的方法)使用WebGetWebInvoke(Method="GET")存在差异。

With WebInvoke the request goes through different pipeline in WCF stack, trying to deserialize the expected message (method IDispatchMessageFormatter.DeserializeRequest() gets invoked) which is not the case with WebGet . 使用WebInvoke ,请求通过WCF堆栈中的不同管道,尝试反序列化预期的消息(方法IDispatchMessageFormatter.DeserializeRequest()被调用),这与WebGet

The lesson learned: use WebGet for GET operation 吸取的教训是:使用WebGet进行GET操作

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

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