Is it true that the WebInvoke attribute can take GET as a method? I can't see any notion of this in Microsoft documentation. I have seen it used in some forum examples though.
In principle, shouldn't it be so, that when using webInvoke you are able to post,put, and delete. When using WebGet in contrast, you are only able to use the GET verb over HTTP, meaning that you cannot Post, Delete and Put. Now Get-operations should not modify data, they should according to to W3org be idempotent, and for that reason not be an an option in the WebInvoke attribute. Can someone point out the role or existence of the GET verb in WebInvoke attributes, and especially in the context of REST programming.
WebInvoke
is general attribute for any HTTP verb including GET. If you use it with GET you must follow all GET's limitations - operation parameters must be simple types mapped to URI path arguments.
WebGet
is just for GET verb and IMHO it exists mostly to show the difference between GET and other verbs (GET should be idempotent, GET doesn't have body, etc.)
The most significant method in .NET using these attributes is internal GetWebMethod
:
internal static string GetWebMethod(OperationDescription od)
{
WebGetAttribute wga = od.Behaviors.Find<WebGetAttribute>();
WebInvokeAttribute wia = od.Behaviors.Find<WebInvokeAttribute>();
EnsureOk(wga, wia, od);
if (wga != null)
{
return "GET";
}
if (wia == null)
{
return "POST";
}
return (wia.Method ?? "POST");
}
As you can see GET method for WebInvoke
is normally processed.