How can I force WCF to autogenerate WSDLs with required method parameters (minoccurs=“1”)?

后端 未结 2 1809
太阳男子
太阳男子 2020-12-05 11:03

While using WCF and OperationContracts I have the following method defined:

    [OperationContract]
    [FaultContract(typeof(ValidationFault))]
    [FaultCo         


        
相关标签:
2条回答
  • 2020-12-05 11:39

    Check that MyComplexType is marked with a [DataContract] attribute.

    For my own WCF contract, I found that minOccurs = 1 would not show up for IsRequired=true in the generated wsdl until the whole chain of objects implicated in the contract were marked as such.

    0 讨论(0)
  • 2020-12-05 11:52

    I've just written a Blog post about this subject, as I ran into the problem myself last week. It explains how you can modify the metadata that WCF generates at runtime.

    Aside from downloading the source file, you only need to add an attribute to your contract definition. Like so:

    [ServiceContract]
    [RequiredParametersBehavior]
    public interface ICalculatorService
    {
        [OperationContract]
        int Add(int firstValue, int secondValue);
    }
    

    Here's the Blog post that explains it in more detail: Controlling WSDL minOccurs with WCF

    0 讨论(0)
提交回复
热议问题