Shiraz Bhaiji
Shiraz Bhaiji

Reputation: 65461

WCF Contract restrict string values

We are defining some WCF contracts for a project.

In one case we want so send over a status field. We though of just sending this over as a text.

We will be interoperating with java web services.

Upvotes: 0

Views: 349

Answers (1)

Drew Marsh
Drew Marsh

Reputation: 33379

No you can't, but you could use enums which are then turned into the schema equivalent of a restricted list of strings. This is also helpful to non-WCF clients because they can easily see what the range of allowed string values are.

Unfortunately enums come with some unfortunate baggage in WCF when it comes to versioning. Specifically, you can't just add a new enum and not break existing WCF clients. So adding a new enum is considered a breaking change.

You will need to weigh these two options and decide which is best for you. If you choose "pure" string, then you will need to validate the values yourself. This can be done generically by writing an IParameterInspector which you can hook to all your services that might use the data contract that you're interested in constraining.

Upvotes: 4

Related Questions