There is still no way to inform the consumer about the consumption of data restrictions?
This question, of course, is a duplicate of others that have never been answered, or at least 5 years old, without a viable solution. Links are outdated or not useful or relate to .Net 3.x, and then we could not do anything.
To be clear, this is NOTHING for validation by the service ... please do not go there. This only applies to the fact that the client learns about the restrictions through the automatically generated WSDL / XSD .
Given the following WCF service, StringLength, Range, and DefaultValue are specified.
VB Version:
<ServiceContract([Namespace]:="example.com")> Public Interface IWCF_Service <OperationContract()> Function Test1(Value As Something) As String Class Something <StringLength(50), DefaultValue("Whatever")> Public Property Thing1 As String = "Whatever" <Range(5, 50), DefaultValue(10), Required> Public Property Thing2 As Int32 = 10 End Class End Interface
C # Version:
[ServiceContract(Namespace = "example.com")] public interface IWCF_Service { [OperationContract()] string Test1(Something Value); public class Something { [StringLength(50), DefaultValue("Whatever")] public string Thing1 { get; set; } [Range(5, 50), DefaultValue(10), Required()] public Int32 Thing2 { get; set; } } }
... the generated XSD lacks default values ββand restrictions, and Thing2 must be minOccurs="1" , because it is required:
<xs:complexType name="IWCF_Service.Something"> <xs:sequence> <xs:element minOccurs="0" name="Thing1" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="Thing2" type="xs:int" /> </xs:sequence> </xs:complexType>
This is what I would expect (or similar):
<xs:complexType name="IWCF_Service.Something"> <xs:sequence> <xs:element minOccurs="0" name="Thing1" nillable="true" default="Whatever"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:maxLength value="50" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="Thing2" default="10"> <xs:simpleType> <xs:restriction base="xs:int"> <xs:minInclusive value="5" /> <xs:maxInclusive value="50" /> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType>