繁体   English   中英

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

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

这个问题已经问到我在问什么,但我想要澄清答案。

答案表明WebGetWebInvoke类似,主要区别在于Method参数。

但是,如果Method参数设置为"GET" ,它实际上是功能相同的,还是存在其他差异?

它们只是标记属性,最终在功能上等同于100%。 解释这些属性的唯一因素是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";
}

它不是。

我花了几个小时尝试使用MessageFormatter基于示例使用Newtonsoft JsonSerializer替换WCF DataContractJsonSerializer

发现(困难的方法)使用WebGetWebInvoke(Method="GET")存在差异。

使用WebInvoke ,请求通过WCF堆栈中的不同管道,尝试反序列化预期的消息(方法IDispatchMessageFormatter.DeserializeRequest()被调用),这与WebGet

吸取的教训是:使用WebGet进行GET操作

暂无
暂无

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

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