C# WebGet在功能上是否等同于WebInvoke(方法=";GET";)?

C# WebGet在功能上是否等同于WebInvoke(方法=";GET";)?,c#,.net,wcf,webinvoke,webget,C#,.net,Wcf,Webinvoke,Webget,这个问题已经问到我在问什么了,但我想澄清一下答案 答案是WebGet和WebInvoke相似,主要区别在于方法参数 但是如果方法参数设置为“GET”,它实际上是功能等效的,还是有其他区别?它们只是标记属性,最终是100%功能等效的。解释这些属性的唯一方法是WebHttpBehavior::GetWebMethod方法,其功能很简单: internal static string GetWebMethod(OperationDescription od) { WebGetAttribute

这个问题已经问到我在问什么了,但我想澄清一下答案

答案是
WebGet
WebInvoke
相似,主要区别在于
方法
参数


但是如果
方法
参数设置为
“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";
}
内部静态字符串GetWebMethod(操作描述od)
{
WebGetAttribute WebGetAttribute=od.Behaviors.Find();
WebInvokeAttribute WebInvokeAttribute=od.Behaviors.Find();
EnsureOk(webGetAttribute、webInvokeAttribute、od);
如果(webGetAttribute!=null)
{
返回“GET”;
}
如果(webInvokeAttribute==null)
{
返回“POST”;
}
返回webInvokeAttribute.Method??“POST”;
}
它不是

我只是花了几个小时尝试使用基于和的MessageFormatter将WCF DataContractJsonSerializer替换为Newtonsoft JsonSerializer 样品

发现使用
WebGet
WebInvoke(Method=“GET”)
有区别(很困难)

使用
WebInvoke
时,请求通过WCF堆栈中的不同管道,试图反序列化预期消息(方法
IDispatchMessageFormatter.DeserializerRequest()
被调用),而
WebGet
则不是这样


经验教训:使用
WebGet
进行
GET
操作

的文档中说:“如果希望服务操作响应GET,请使用WebGetAttribute。”因此,WebInvoke似乎只用于POST、PUT或DELETE。一个区别是:内部方法将WebGet视为GET和WebInvoke(即使它的方法是GET)as POST。@MichaelLiu是的,我读过,但是代码已经包含
WebInvoke(Method=“GET”)
,所以我想在更改之前确保我没有破坏任何东西