[英]Are there any constants in the .NET framework for the different web method types (GET, PUT, POST, DELETE, HEAD)?
I just noticed while creating a RESTful WCF service that the Method parameter on the WebInvoke
attribute is case sensitive (CAPS required). 我刚刚注意到在创建RESTful WCF服务时, WebInvoke
属性上的Method参数区分大小写(需要CAPS)。
So, 所以,
[WebInvoke(Method = "Delete")]
is not equal to 不等于
[WebInvoke(Method = "DELETE")]
This mistake was causing a ProtocolException
: 这个错误导致了ProtocolException
:
System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed. System.ServiceModel.ProtocolException:远程服务器返回了意外响应:(405)Method Not Allowed。
I was wondering is there a set of constants in the .NET framework that I should be using in place of "DELETE" in the above example. 我想知道在.NET框架中是否有一组常量我应该用来代替上面例子中的“DELETE”。 I could of course define my own set of constants, but if feels like something that probably exists in the framework and I am just missing it. 我当然可以定义我自己的常量集,但如果感觉像框架中可能存在的东西,我只是错过了它。
A bit indirect, but there are System.Net.WebRequestMethods.Http
constants: 有点间接,但有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";
but no "DELETE" - suggest you make your own... 但没有“删除” - 建议你自己制作......
Annoyingly, there is a System.Web.HttpVerb
, but it is internal
, so not usable - and it is an enum, so to use the name in an attribute you'd need a bit of hackery. 令人讨厌的是,有一个System.Web.HttpVerb
,但它是internal
,所以不可用 - 它是一个枚举,所以要在属性中使用你需要一些hackery的名称。
The System.Web.Mvc namespace has HttpVerbs. System.Web.Mvc命名空间具有HttpVerbs。 https://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs(v=vs.118).aspx The reference can be selected under Assemblies, Extensions https://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs(v=vs.118).aspx可以在Assemblies,Extensions下选择引用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.