Reputation: 56
Normally you check incoming parameters in your public methods using if-then-throw
pattern or Code Contracts.
My question is, how should I validate parameters passed in my WCF service? For example, I've got the following contract:
[OperationContract]
Stock GetStock(string symbol);
I want to ensure that symbol
parameter is not null
or empty string. Should I use the same if-then-throw
pattern or Code Contracts precondition on the service-side? Should I add a FaultContract
attribute to the GetStock
method and return a fault to the client? What's the best parameters validation technique for WCF service?
Upvotes: 1
Views: 8513
Reputation: 5801
Enterprise Library Validation Application Block has an adaptor for integration with WCF designed for exactly this.
This CodeProject Introduction is a little old but gives a bit more background than the MSDN links.
Upvotes: 5