Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

So,

[WebInvoke(Method = "Delete")]

is not equal to

[WebInvoke(Method = "DELETE")]

This mistake was causing a ProtocolException:

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (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. 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.

like image 404
Eric Schoonover Avatar asked Feb 01 '09 09:02

Eric Schoonover


People also ask

What are the four ities of .NET framework?

The Four “ities”. The four “ities” are Reliability, Compatibility, Scalability, and Security. The . NET Framework is a highly scalable and reliable platform as it secures its applications by assigning access rights to specific users.

Which ASP NET core no longer depends on the system?

Fast: ASP.NET Core no longer depends on System. Web. dll for browser-server communication. ASP.NET Core allows us to include packages that we need for our application.


1 Answers

A bit indirect, but there are System.Net.WebRequestMethods.Http constants:

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.

like image 60
Marc Gravell Avatar answered Oct 24 '22 01:10

Marc Gravell