Reputation: 35
I am currently working on a project where a previous developer used a * for the Method of a WebInvoke.
[OperationContract]
[WebInvoke(Method = "*", UriTemplate = "/Path", ResponseFormat = WebMessageFormat.Json)]
void SetPath(PathInfo pathInfo);
I am wondering what the * is for - if anything. I was expecting GET, PUT, POST, etc... not star. Initially I was thinking default (POST), but there is no reason to use * if the it is the same as default.
MSDN does not seem to address it (MSDN WebInvokeAttribute.Method), but they don't really address any of the methods except POST which is the default.
This post (Implementing Method) seems to indicate that the * should be used with the OPTIONS method as the UriTemplate. So, I am just trying to figure out if he is incorrect or if his code is valid in which case I would like to know what it means.
Upvotes: 2
Views: 1374
Reputation: 21
Using WebInvoke(method=""... is the way to support CORS requests (Preflight, method='OPTIONS') from the browser. Using '' on your service method will route the CORS preflight request into your service method (in addition to the get/post/put etc.) and will let you handle the preflight. Otherwise, your method will not be called on preflight requests, and the preflight will fail (in the browser)
Upvotes: 0
Reputation: 16033
I decompiled the System.ServiceModel.Description.WebHttpBehavior
which uses WebInvoke
and you can see that this is just a wildcard action matching everything.
public class WebHttpBehavior : IEndpointBehavior, IWmiInstanceProvider
{
internal const string GET = "GET";
internal const string POST = "POST";
internal const string WildcardAction = "*";
internal const string WildcardMethod = "*";
This is a catch all behavior
Upvotes: 1