How to specify a parameter of an OperationContract as required
You might need to wrap your parameters in a class, then you can use the DataMember
attribute and specify IsRequired=true
:
[ServiceContract(Namespace = "http://myUrl.com")]
public interface IMyWebService
{
[OperationContract]
string DoSomething(RequestMessage request);
}
[DataContract]
public class RequestMessage
{
[DataMember(IsRequired = true)]
public string param1 { get; set; }
[DataMember(IsRequired = true)]
public string param3 { get; set; }
[DataMember(IsRequired = true)]
public string param3 { get; set; }
}
This implementation is nice to me: http://thorarin.net/blog/post/2010/08/08/Controlling-WSDL-minOccurs-with-WCF.aspx