Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to generate custom collection type in .Net from WSDL?
    text
    copied!<p>I am running a custom application that imports WSDLs and generates C# source code, using WSDLImporter class to read in contracts. </p> <p>XSD sequence types are translated into native arrays. What options can I set in order to be able to generate custom collection types?</p> <p>Schema:</p> <pre><code>&lt;xs:complexType name="getAllSourcesResponse"&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="tns:Source"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>becomes code:</p> <pre><code>public partial class getAllSourcesResponse { [System.Xml.Serialization.XmlElementAttribute("return", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] public PaymentSource[] @return; public getAllSourcesResponse() { } public getAllSourcesResponse(Source[] @return) { this.@return = @return; } } </code></pre> <p>I looked into SvcUtil.exe code, it appears to do the following, but it does not seem to make any difference in what code my application produces.</p> <pre><code>WsdlImporter importer = ... XsdDataContractImporter contractImporter = new XsdDataContractImporter(codeCompileUnit); ImportOptions importOptions = new ImportOptions(); importOptions.ReferencedCollectionTypes.Add( typeof(System.Collections.Generic.IList&lt;&gt;)); contractImporter.Options = importOptions; importer.State.Add(typeof(XsdDataContractImporter), contractImporter); </code></pre> <hr> <p>@CasperOne, this schema snippet</p> <pre><code>&lt;xs:complexType name="getClassesForPackageResponse"&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="xs:string"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; </code></pre> <p>generates a string[] type: </p> <pre><code>public partial class getClassesForPackageResponse { public string[] @return; public getClassesForPackageResponse() {} public getClassesForPackageResponse(string[] @return) { this.@return = @return; } } </code></pre> <p>This does not cause string collection to use List: </p> <pre><code>ImportOptions importOptions = new ImportOptions(); importOptions.ReferencedCollectionTypes.Add( typeof(System.Collections.Generic.List&lt;string&gt;)); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload