2

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.

netfed
  • 602
  • 8
  • 18

1 Answers1

4

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.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Perfect. Thank you very much, and especially for the explaining code. So when using WebInvoke and WebGet in other words, WebInvoke and WebGet goes to a dispatch-routine where the attributes are examined (attributes here are 'get' or 'post'), and the result of this examination is decisive for the further interpretation of the "command". GetWebMethod is a kind of framework-internal filter then. Where can we see GetWebMethod? I guess by studing the serviceModel class hierarchy. – netfed Apr 14 '12 at 07:49
  • 1
    `GetWebMethod` is internal method inside WCF - you will find it with tool like Reflector. – Ladislav Mrnka Apr 15 '12 at 21:18