I have a WCF Web API. Some endpoints accept DataContracts which obviously contain different properties and datatypes. If a request contains a property with an incorrect data type (ie A string in an integer property) the value comes through as null after being serialized. Is there a simple way to instead, throw back a HTTP 400 Bad Request response (and possibly the offending property).
Thanks
There are several ways :
if(param == null){
throw new HttpException(400, "Bad Request, param is invalid");
//or
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad Request, param is invalid");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.