I have the following type in wsdl (it is generated by third party tool):
<xsd:complexType name="IntArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
Sometimes Visual Studio generates:
public class IntArray : System.Collections.Generic.List<int> {}
And sometimes it doesn't generate any proxy type for this wsdl and just uses int[].
Collection type in Web Service configuration is System.Array.
What could be the reason for such upredictable behavior?
Edited:
I found the way how I can reproduce this behavior.
For examle we have two types:
<xsd:complexType name="IntArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:int" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="StringArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
VS generates:
public class IntArray : System.Collections.Generic.List<int> {}
public class StringArray : System.Collections.Generic.List<string> {}
Now I change StringArray type:
<xsd:complexType name="StringArray">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Elements" type="xsd:string" />
<xsd:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
</xsd:sequence>
<xsd:anyAttribute namespace="##any" processContents="lax"/>
</xsd:complexType>
VS generates proxy type for StringArray only. But not for IntArray.
Edited:
Reference.svcmap:
<ClientOptions>
<GenerateAsynchronousMethods>false</GenerateAsynchronousMethods>
<EnableDataBinding>true</EnableDataBinding>
<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateMessageContracts>false</GenerateMessageContracts>
<NamespaceMappings />
<CollectionMappings />
<GenerateSerializableTypes>true</GenerateSerializableTypes>
<Serializer>Auto</Serializer>
<ReferenceAllAssemblies>true</ReferenceAllAssemblies>
<ReferencedAssemblies />
<ReferencedDataContractTypes />
<ServiceContractMappings />
</ClientOptions>
If you view all files for the project and then view the file called Reference.svcmap for the appropriate service reference could you please let me know what the following config options are in the xml?
<ExcludedTypes />
<ImportXmlTypes>false</ImportXmlTypes>
<GenerateInternalTypes>false</GenerateInternalTypes>
<GenerateSerializableTypes>false</GenerateSerializableTypes>
<Serializer>Auto</Serializer>
Sorry about putting it in as an answer but it was horribly unreadable in the comments.
Edit
Ok, so what is happening here is following:
In your case, adding the xsd:any element is causing the serialization mode to change. If you want consistent serialization, you will have to remove the forbidden element or force the proxy generation to use XmlSerialization all the time.
Here is a link about the allowable schema elements for the DataContractSerializer.
Cheers -Leigh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With