Nick LaMarca
Nick LaMarca

Reputation: 8188

Input Validation WCF

It seems that is you mark a DataMember property in an object you create and use the IsRequired attribute, you are only telling the comsumer that the tag for this proerty needs to be in the input schema. I need to tell the customer is not only needs to be in the input schema it needs to be populated with a value. And even further why not have a regular expression to check against?

Can someone give me a sample on how to tell the consumer of a WCF method input validation for the value being pass?

Upvotes: 2

Views: 2295

Answers (2)

Randolpho
Randolpho

Reputation: 56391

The best approach to input validation in WCF is to use a custom schema validator. Microsoft has a tutorial on the subject here:

http://msdn.microsoft.com/en-us/library/ff647820.aspx

Note: as RQDQ mentioned, this is non-trivial. However, the approach outlined in the link above is at the very least fairly modular.

Upvotes: 2

RQDQ
RQDQ

Reputation: 15569

There is no such mechanism at the current time in WCF (at least that I know of).

What you're describing is very non-trivial. For example, the same data control might be used by more than one operation. Each operation might specify a different set of requirements for what is valid input. Those requirements may be very complicated (e.g. some fields are required given the value of other fields on that or another DataContract).

There is no free lunch here - API documentation is the only way I know of to specify this level of information.

Upvotes: 0

Related Questions