![](/img/trans.png)
[英]Why is this method not allowed for WebInvoke, but OK for WebGet?
[英]Is WebGet functionally equivalent to WebInvoke(Method = “GET”)?
这个问题已经问到我在问什么,但我想要澄清答案。
答案表明WebGet
和WebInvoke
类似,主要区别在于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";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.