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”)
,所以我想在更改之前确保我没有破坏任何东西