ASMX-generated WSDL not compatible with the XML Schema file

Topics: General Discussion Forum, July and December Releases Forum
Feb 1, 2007 at 12: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:sequence>
<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:sequence>
<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?

Regards
Feb 1, 2007 at 6:34 PM
Edited Feb 2, 2007 at 6: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: http://msdn2.microsoft.com/en-us/zds0b35c.aspx

IsNullable:
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.isnullable.aspx

More about ASMX-style services at my blog:
http://kjellsj.blogspot.com/2006/12/how-to-expose-wcf-service-also-as-asmx.html


KjellSJ