POST
WCF を使用して REST サービスを開発していますが、無効な場合に返さなければならない HTTP ステータス コードの種類がわかりませんMessage
。注: ここでのメッセージは、チャット メッセージ (テキストといくつかのデータ) のようなものです。
これは、WCF サービスを実装した方法です。
IServiceContract :
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/messages",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
Message AddMessage(Message message);
サービスの実装:
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;
}
今私はRequestedRangeNotSatisfiable
(HTTP 416)を使用しています。しかし、これが無効なを POST したときに返される HTTP ステータス コードであるかどうかはわかりませんMessage
。
無効なオブジェクトを POST する場合、どのような HTTP ステータス コードを返す必要がありますか?