.net - Adding restrictions to xsd generated from wcf -


so i'm doing research on how format wsdl , xsd generated wcf, adding annotations/documentation wsdl , xsds along adding restrictions various parameters.

so far i've been able add documentation both wsdl , xsds creating attributes implement iwsdlexportextension interface along ioperationbehavior interface.

for general idea of modifying schemas see:
http://thorarin.net/blog/post/2010/08/08/controlling-wsdl-minoccurs-with-wcf.aspx

for general idea of adding annotations wsdl see:
http://msdn.microsoft.com/en-us/library/ms731731(v=vs.110).aspx

however run trouble when trying add restrictions elements(by adding simple types) in xsd.

from here can either exception occur stating can't set elements type because has read-only type associated it, or can try using read-only type add restriction, nothing happens.

here's code generating exception (system.xml.schema.xmlschemaexception: type attribute cannot present either simpletype or complextype.) :

    var complextype = ((xmlschemaelement)schema.elements[parameter.xmlqualifiedname]).elementschematype xmlschemacomplextype;     var sequence = complextype.particle xmlschemasequence;      foreach (xmlschemaelement item in sequence.items)     {         if (item.name = parameter.name && parameter.length > 0)         {             xmlschemasimpletype temptype = new xmlschemasimpletype();             xmlschemasimpletyperestriction temprestriction = new xmlschemasimpletyperestriction();             xmlschemalengthfacet lengthfacet = new xmlschemalengthfacet();             temptype.content = temprestriction;             temprestriction.facets.add(lengthfacet);             lengthfacet.value = "" + parameter.length;              item.schematype = temptype; // <-- problem code           }          ...      } 

and here's work around nothing:

    var complextype = ((xmlschemaelement)schema.elements[parameter.xmlqualifiedname]).elementschematype xmlschemacomplextype;     var sequence = complextype.particle xmlschemasequence;      foreach (xmlschemaelement item in sequence.items)     {         if (item.name = parameter.name && parameter.length > 0)         {             xmlschemasimpletyperestriction temprestriction = new xmlschemasimpletyperestriction();             xmlschemalengthfacet lengthfacet = new xmlschemalengthfacet();             temprestriction.basetypename = new xmlqualifiedname("string", "http://www.w3.org/2001/xmlschema");             temprestriction.facets.add(lengthfacet);             lengthfacet.value = "" + parameter.length;              // appears nothing             ((xmlschemasimpletype)item.elementschematype).content = temprestriction;           }          ...      } 

quick other note: if switch normal loop , try replace trouble element new element (hackish know...), following exception: system.invalidcastexception: unable cast object of type 'system.xml.schema.xmlschemasimpletype' type 'system.xml.schema.xmlschemaparticle'. 1 i'm more curious since both should xmlschemaelements right?

so basically, know how add simple types/add simple type restrictions xmlschemaelements , have show in xsds generated wsdl wcf?

thanks!


edit: added
temprestriction.basetypename = new xmlqualifiedname("string", "http://www.w3.org/2001/xmlschema");

in second example, don't forget

temprestriction.basetypename = new xmlqualifiedname("string", "http://www.w3.org/2001/xmlschema"); 

before defining facets. restriction not separate schema object, derivation method. derives own simple type pre-existing simple type such string.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -