1

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Can Data Annotaion do this job?
You can use it for validation, but its in a different technology stack from WCF. System.ComponentModel.DataAnnotations is for ASP.NET MVC and ASP.NET data controls.
For anybody getting a "operation.SyncMethod" error with VAB and WCF, VAB does not seem to support async, alternatively look at Validating wcf service operations using system.componentmodel.dataannotations

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.