.NET框架中是否有针对不同Web方法类型(GET,PUT,POST,DELETE,HEAD)的常量?

Eri*_*ver 15 .net c# wcf constants

我刚刚注意到在创建RESTful WCF服务时,WebInvoke属性上的Method参数区分大小写(需要CAPS).

所以,

[WebInvoke(Method = "Delete")]
Run Code Online (Sandbox Code Playgroud)

不等于

[WebInvoke(Method = "DELETE")]
Run Code Online (Sandbox Code Playgroud)

这个错误造成了ProtocolException:

System.ServiceModel.ProtocolException:远程服务器返回了意外响应:(405)Method Not Allowed.

我想知道在.NET框架中是否有一组常量我应该用来代替上面例子中的"DELETE".我当然可以定义我自己的常量集,但如果感觉像框架中可能存在的东西,我只是错过了它.

Mar*_*ell 12

有点间接,但有System.Net.WebRequestMethods.Http常量:

public const string Connect = "CONNECT";
public const string Get = "GET";
public const string Head = "HEAD";
public const string MkCol = "MKCOL";
public const string Post = "POST";
public const string Put = "PUT";
Run Code Online (Sandbox Code Playgroud)

但没有"删除" - 建议你自己制作......

令人讨厌的是,有一个System.Web.HttpVerb,但它是internal,所以不可用 - 它是一个枚举,所以要在一个属性中使用你需要一些hackery的名称.