Hi all,

I'm developing a C# WCF web service in which I need to put some length
restrictions on some elements.
Accoring to MSDN http://msdn.microsoft.com/en-us/library/ms733112.aspx
maxLength, minLength and length etc are ignored.

My code looks like this:
C#:
    [DataContract(Name = "ServiceCredentials", Namespace = "http://
tempuri.org/ns/ServiceCredentials")]
    public class ServiceCredentials
    {
        private string _username;
        [DataMember(IsRequired = true, Order = 0, Name = "Username")]
        public string Username { get { return _username; } set
{ _username = value; } }
        private string _passwd;
        [DataMember(IsRequired = true, Order = 1, Name = "Password")]
        public string Password{ get { return _passwd; } set { _passwd=
value; } }
    }

Generated in WSDL:
<?xml version="1.0" encoding="utf-8"?>
  <xs:schema
    elementFormDefault="qualified"
    targetNamespace="http://tempuri.org/ns/ServiceCredentials";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:tns="http://tempuri.org/ns/ServiceCredentials";>
  <xs:complexType name="ServiceCredentials">
     <xs:sequence>
       <xs:element name="Password" nillable="true" type="xs:string"/>
       <xs:element name="Username" nillable="true" type="xs:string"/>
     </xs:sequence>
  </xs:complexType>
  <xs:element name="ServiceCredentials" nillable="true"
type="tns:ServiceCredentials"/>
</xs:schema>

What I need is a way to specify minLength and maxLength. My WDSL will
more or less look like this than:

<?xml version="1.0" encoding="utf-8"?>
  <xs:schema
    elementFormDefault="qualified"
    targetNamespace="http://tempuri.org/ns/ServiceCredentials";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    xmlns:tns="http://tempuri.org/ns/ServiceCredentials";>
  <xs:complexType name="ServiceCredentials">
     <xs:sequence>
       <xs:element name="Password" nillable="true" type="xs:string"/>
       <xs:element name="Username" nillable="true"
type="UsernameElement"/>
     </xs:sequence>
  </xs:complexType>
  <xs:element name="ServiceCredentials" nillable="true"
type="tns:ServiceCredentials"/>
  <xs:simpleType  name="UsernameElement">
      <xs:restriction base="xs:string">
        <xs:minLength value="2"/>
        <xs:maxLength value="10"/>
      </xs:restriction>
  </xs:simpleType>
</xs:schema>

Does anyone know how to specify the restrictions minLength and
maxLength in a way they are accepted into the WSDL?

Any input is more than welcome!
Thanks for your time in advance.

Gyldor

Reply via email to