c# - How to specify a parameter of an OperationContract as required -
I wonder how can I specify the parameters of the operation contract method in WCF so that xsd generated minOccurs = "1 Example:
  [communication of service (namespace = "http://myUrl.com")] Public Interface IMyWebService {[Operation Contract] string DoSomething (string Absolute 1, string paragraph 2, string paragraph 3); }   Generates the XSD:
    
But I want to define minOccurs = "1" in the code without needing to manually fix it in the xsd file.
 You may need to wrap your parameters in the class, then you  DataMember  attribute and specify  IsRequired = true : 
  [communication of service (namespace = "http://myUrl.com" )] Public Interface IMyWebService {{OperationContract} string DoSomething (RequestMessage Request); } [DataContract] Public class request message [[DataRequired = true] Public string parameter1 {get; Set; } [DataMember (IsRequired = true)] Public String param3 {get; Set; } [DataMember (IsRequired = true)] Public String param3 {get; Set; }}   
Comments
Post a Comment