I am trying to generate DataContract annotated classes based on my xsd files. These classes should then be used as exchange data types for my Soap web services.
In cmd.exe I've tried running the command:
svcutil /dconly loginSoap.xsd /language:C#
But it fails with the following error:
Error: Type 'loginRequest' in namespace 'http://www.megatravel.xyz/XMLSchema/XMLSchemaSoap/Login' cannot be imported. The root particle must be a sequence. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer.
If you are using the /dataContractOnly option to import data contract types and are getting this error message, consider using xsd.exe instead. Types generated by xsd.exe may be used in the Windows Communication Foundation after applying the XmlSerializerFormatAttribute attribute on your service contract. Alternatively, consider using the /importXmlTypes option to import these types as XML types to use with DataContractFormatAttribute attribute on your service contract.
My xsd file is:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.megatravel.xyz/XMLSchema/XMLSchemaSoap/Login"
targetNamespace="http://www.megatravel.xyz/XMLSchema/XMLSchemaSoap/Login"
elementFormDefault="qualified">
<xs:element name="loginRequest">
<xs:complexType>
<xs:all>
<xs:element name="username" type="xs:string"/>
<xs:element name="password" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="loginResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The error points you in the right direction.
Just replace <xs:all>
with <xs:sequence>
or use XSD.exe with /classes