Rolling Your Own Status

I’m trying to use an HTTP method that has defined a private protocol for status code. What can I do if the HttpStatusCode class doesn’t have the necessary value?

The HttpStatusCode enumeration contains predefined constants for the status codes described by the HTTP 1.1 standard. Here you can take advantage of the fact that an enumeration is by default an integer-typed value to make use of your own custom status codes. This probably only makes sense if you’re not using SOAP as the envelope format because SOAP defines an expected set of status codes for the response when using HTTP.

HttpResponseMessageProperty p = new HttpResponseMessageProperty();
p.StatusCode = (HttpStatusCode)555;
OperationContext.Current.OutgoingMessageProperties[HttpResponseMessageProperty.Name] = p;
Comments (2)

  1. Colin Bowern says:

    Have you noticed that on Casini that you cannot output your own status description though?  If I change the status code to "500" and put a custom error message it disregards that message.

  2. Hi Colin,

    The test server is limited in a lot of ways.  It has grown to be used far more than originally envisioned.  It’s more useful for quick debugging than comprehensive testing of the service code.