I'm developing a REST service using WCF and I don't know which type of HTTP Status Code do I have to return when I POST an invalid Message. Note: A message here is like a chat message (a text and some data).
This is how I have implemented the WCF Service:
IServiceContract:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/messages",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
Message AddMessage(Message message);
Service Implementation:
public Message AddMessage(Message message)
{
OutgoingWebResponseContext ctx =
WebOperationContext.Current.OutgoingResponse;
if (message == null)
{
ctx.StatusCode = System.Net.HttpStatusCode.RequestedRangeNotSatisfiable;
ctx.StatusDescription = "message parameter is null";
throw new ArgumentNullException("message", "AddMessage: message parameter is null");
}
using (var context = new AdnLineContext())
{
context.Entry(message).State = EntityState.Added;
context.SaveChanges();
}
return message;
}
Now I use RequestedRangeNotSatisfiable (HTTP 416). But I don't know if this is the HTTP Status code to return when I POST an invalid Message.
What kind of HTTP Status code do I have to return when I POST an invalid object?