0

In a Wcf service I have the following ServiceContract:

[ServiceContract]
public interface IFooBarService
{ 
    [OperationContract]
    bool SetFooBar(FooBar fb);
}

[DataContract]
public class FooBar 
{
    [DataMember]
    public string ExternalId;
    [DataMember]
    public string Something;
    [DataMember]
    public List<Foo> Foos;
    [DataMember]
    public List<Bar> Bars;
}

I want to prevent The consumer of the Web Service from sending me List of null Foo/Bar Object. Is there any annotation to enforce this rules?

xdtTransform
  • 1,986
  • 14
  • 34
  • [No, but there are workarounds](https://stackoverflow.com/questions/12836534/wcf-is-there-an-attribute-to-make-parameters-in-the-operationcontract-required) – stuartd May 25 '18 at 12:02
  • Well unfortunatly it's not a dupe, as here I don't care if he send me Foos just that this list of Foo is not a brunch of Null. It's not about been required. – xdtTransform May 25 '18 at 12:29
  • Can't you just throw a FaultException if it's null? You can't stop the client from sending a null value. – stuartd May 25 '18 at 12:31
  • I will just check and ignore the null as I can't ask them to handle an exception. Well Lets close it as dupe as answer there will be fit. – xdtTransform May 25 '18 at 12:38

0 Answers0