WCF: is there an attribute to make parameters in the OperationContract required?

后端 未结 2 1258
遇见更好的自我
遇见更好的自我 2020-12-19 03:08

I use [DataMember(IsRequired=true)] to make the DataContract properties required. There doesn\'t seem to be some IsRequired for the OperationContract parameters

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 03:58

    Unfortunately it can't be done using default WCF. There exist a few workarounds:

    • A custom RequiredParametersBehavior attribute
    • Using the Validation Application Block from the Enterprise Library and associate a ruleset to your method

    You can however implement a FaultContract and throw a fault when the input parameter is null.

提交回复
热议问题