質問

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.

  • Can we specify in the WCF contract that only these x string valuses are allowed?
  • Would it be better to use enums?

We will be interoperating with java web services.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top