Bruce Hunter - 318 - Feb 12, 2014

Suppose you have a Guid type exposed and a client sends a malformed Guid value to the service. The service is unable to cast this and the property remains null. Is this correct?

Is there a way to capture this process and return validation in the responseStatus as short circut? Otherwise, the property gets set to null and my other lower level validation is being fired and i’m not sure if the object was null because the client sent it as null or there was an invalid cast and it got set to null. This would change how the message is presented back to the client as to what is happening.

Wayne Brantley:

I think the only way to know would be to look at the raw request data and inspect to see if that GUID was sent…if it was sent and it is null, it is because of an invalid cast…?

Stephen Brannan:

Another option (I’ll admit not the greatest) is to declare it as a string on your request model and then do your validation in the service call.

You can register your own request binder:
But that would mean you would have to take care of the deserialization yourself.

Like Stephen says you can specifying a string and convert it to a Guid yourself. 

You could also buffer the Request body and inspect it yourself using JsonObject.Parse(json)[“Id”] for JSON.

Bruce Hunter:

Thanks guys!