How to set minOccurs to 1

后端 未结 3 1170
慢半拍i
慢半拍i 2021-01-15 16:09

I\'m building an ASP.NET web service.

I\'ve got my code defined as below, but I can\'t figure out how to the the wsdl to specify the minOccurs of the FirstName and

相关标签:
3条回答
  • 2021-01-15 16:37

    I have posted the detailed answer on another thread with the same problem: How to make a dotnet webservice set minOccurs=“1” on a string value.

    However the answer for strings is no.

    The only way make minOccurs=1 without nullable=true is to declare a property with no default value (string has a default value of String.Empty) and without a property to check if the value was specified (making an identical property name with "Specified" word appended to it's name).

    And you are still limited if John Saunders' answer is true.

    It turns out that the WSDL is not used to validate incoming XML. It wouldn't matter whether or not you could specify minOccurs - it would not be used to validate the input.

    0 讨论(0)
  • 2021-01-15 16:37

    It turns out that the WSDL is not used to validate incoming XML. It wouldn't matter whether or not you could specify minOccurs - it would not be used to validate the input.

    0 讨论(0)
  • 2021-01-15 16:42

    Strings are reference types and so by definition nullable. If your property was an integer minoccurs would have been 1.

    You can force the Serializer not to allow it to be null, by putting. [XmlElement("name", IsNullable=false)]
    above the property.

    Edit: I meant reference types instead of value types. Thnx Joren!

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