mr goose
mr goose

Reputation: 56

How should I validate parameters passed into my WCF service?

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 symbolparameter 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

Answers (1)

ErnieL
ErnieL

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

Related Questions