1. Required parameter
In the following example URI definition
[WebGet(UriTemplate = "GetData?value={value}")]
[OperationContract]
string GetData(int value);
{
return string.Format("You entered: {0}, value);
}
the "value" parameter is optional by default, and if I don't pass it (call to http://baseAddress/GetData
), the variable is filled with zero.
Is there any easy way to make this parameter required, maybe an attribute? The only way I found is to manually check WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["value"] != null
.
2. HTTP 400 on wrong format
Another thing I hate is that HTTP 500 is returned for /GetData?value=emptyOrAnythingThatIsNotAnInteger
. Can I return HTTP 400 instead? Of course without changing the type to string and checking everything manually.