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?

mr goose
  • 58
  • 4
  • 16

1 Answers1

4

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.

ErnieL
  • 5,773
  • 1
  • 23
  • 27
  • Can `Data Annotaion` do this job? – LCJ Mar 21 '13 at 11:07
  • 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. – ErnieL Mar 21 '13 at 20:24
  • 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](http://www.devtrends.co.uk/blog/validating-wcf-service-operations-using-system.componentmodel.dataannotations) – Schalk Feb 25 '15 at 07:47