ASMX-generated WSDL not compatible with the XML Schema file

Topics: General Discussion Forum, July and December Releases Forum
Feb 1, 2007 at 1:36 PM
I have a problem with the Service Factory (ASMX) and the recipe "Create Data Types From Schemas". The generated WSDL file does not have the right attributes for the elements compared to the XML schema file.

Here is a part from the schema file:
<xs:complexType name="Vardtagardata">
<xs:element minOccurs="1" maxOccurs="1" name="Orgid" type="xs:string" nillable="false" />
<xs:element minOccurs="1" maxOccurs="1" name="Orgnamn" type="xs:string" nillable="false" />
<xs:element minOccurs="1" maxOccurs="1" name="Fornamn" type="xs:string" nillable="false" />

And here is how the same part of the WSDL file looks like:
<s:complexType name="Vardtagardata">
<s:element minOccurs="0" maxOccurs="1" name="Orgid" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Orgnamn" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Fornamn" type="s:string" />

How can I make the element attributes in the WSDL to look the same as the XML schema file?

Feb 1, 2007 at 7:34 PM
Edited Feb 2, 2007 at 7:52 AM
As strings are reference types, not value types, and ASMX uses the XmlSerializer, you can get close by applying XmlElement(IsNullable = true) to the string member. It will give you minOccurs="1" but unfortunately also nillable="true".

Setting IsNullable = false for reference types will give minOccurs="0". For further details about controlling minOccurs and nillable:


More about ASMX-style services at my blog: