WebInvoke 方法 = *
WebInvoke Method = *
我目前正在从事一个项目,之前的开发人员使用 * 作为 WebInvoke 的方法。
[OperationContract]
[WebInvoke(Method = "*", UriTemplate = "/Path", ResponseFormat = WebMessageFormat.Json)]
void SetPath(PathInfo pathInfo);
我想知道 * 是什么意思 - 如果有的话。我期待 GET、PUT、POST 等...不是明星。最初我在考虑默认值 (POST),但如果它与默认值相同,则没有理由使用 *。
MSDN 似乎没有解决它 (MSDN WebInvokeAttribute.Method),但他们并没有真正解决除默认方法 POST 之外的任何方法。
这个post (Implementing Method) 似乎表明 * 应该作为 UriTemplate 与 OPTIONS 方法一起使用。所以,我只是想弄清楚他是否不正确,或者他的代码是否有效,在这种情况下我想知道这意味着什么。
我反编译了使用WebInvoke
的System.ServiceModel.Description.WebHttpBehavior
,你可以看到这只是一个匹配所有内容的通配符操作。
public class WebHttpBehavior : IEndpointBehavior, IWmiInstanceProvider
{
internal const string GET = "GET";
internal const string POST = "POST";
internal const string WildcardAction = "*";
internal const string WildcardMethod = "*";
这是包罗万象行为
使用 WebInvoke(method=""... 是支持来自浏览器的 CORS 请求(Preflight,method='OPTIONS')的方法。使用''在您的服务方法上会将 CORS 预检请求路由到您的服务方法(除了 get/post/put 等)并让您处理预检。否则,您的方法将不会在预检请求上调用,并且预检将失败(在浏览器中)
我目前正在从事一个项目,之前的开发人员使用 * 作为 WebInvoke 的方法。
[OperationContract]
[WebInvoke(Method = "*", UriTemplate = "/Path", ResponseFormat = WebMessageFormat.Json)]
void SetPath(PathInfo pathInfo);
我想知道 * 是什么意思 - 如果有的话。我期待 GET、PUT、POST 等...不是明星。最初我在考虑默认值 (POST),但如果它与默认值相同,则没有理由使用 *。
MSDN 似乎没有解决它 (MSDN WebInvokeAttribute.Method),但他们并没有真正解决除默认方法 POST 之外的任何方法。
这个post (Implementing Method) 似乎表明 * 应该作为 UriTemplate 与 OPTIONS 方法一起使用。所以,我只是想弄清楚他是否不正确,或者他的代码是否有效,在这种情况下我想知道这意味着什么。
我反编译了使用WebInvoke
的System.ServiceModel.Description.WebHttpBehavior
,你可以看到这只是一个匹配所有内容的通配符操作。
public class WebHttpBehavior : IEndpointBehavior, IWmiInstanceProvider
{
internal const string GET = "GET";
internal const string POST = "POST";
internal const string WildcardAction = "*";
internal const string WildcardMethod = "*";
这是包罗万象行为
使用 WebInvoke(method=""... 是支持来自浏览器的 CORS 请求(Preflight,method='OPTIONS')的方法。使用''在您的服务方法上会将 CORS 预检请求路由到您的服务方法(除了 get/post/put 等)并让您处理预检。否则,您的方法将不会在预检请求上调用,并且预检将失败(在浏览器中)