简体   繁体   English

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

[英]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.

相关问题 所有方法都充当ASP.NET WEB API控制器中的HTTP动词(Get,Put,Post和Delete) - All methods act as a HTTP verb (Get, Put, Post And Delete) in ASP.NET WEB API controller ASP.NET Web API如何基于put / get / post / delete从DTO对象中排除属性 - ASP.NET web api how to exclude property from DTO object based on put/get/post/delete ASP.NET Web API:“消息”:“请求的资源不支持 http 方法 'POST'、PUT、DELETE。” 在邮递员 - ASP.NET Web API: "Message": "The requested resource does not support http method 'POST', PUT, DELETE." in Postman 在.NET Web API POST / PUT方法中使用继承的类 - Using inherited classes in .NET web API POST/PUT method PUT 方法可以插入、删除。 那么为什么我们必须使用 POST 方法而不是 PUT/DELETE/GET 方法 - PUT method can insert, delete. then Why we have to use POST method instead of PUT/DELETE/GET method .NET Web API + MySQL:POST/PUT 方法要求太多参数和 GET 方法不提供绑定实体的问题 - .NET Web API + MySQL: Issues with POST/PUT methods asking for too many parameters and GET method not giving binded entities IIS 6.0阻止WCF 4.0 Web服务调用上的PUT和DELETE方法类型 - IIS 6.0 preventing PUT & DELETE method types on WCF 4.0 web service calls Web API控件不能与ASP.NET Web窗体中的POST / PUT / DELETE一起使用 - Web API Controller won't work with POST/PUT/DELETE in ASP.NET Web Forms 从Web Api控制器中的Post方法获取任何参数 - Get any parameter from a Post Method in a Web Api controller Asp.net WEB API - 如果我使用POST而不是PUT和DELETE会出现什么问题? - Asp.net WEB API - What problems could arise if I use POST instead of PUT and DELETE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM