none
XsdDataContractExporter creates extra complex field as compare to SVCUtil.exe in XSD RRS feed

  • Question

  • Hi All,

    I am creating XSD by using XsdDataContractExporter from DLL, but i found that it creates one extra complex element in schema as compare to Svcutil.exe as shown in below image.

    I used Svcutil.exe to create XSD from DLL, which gave correct XSD as shown in below image.

    I am giving you code snippet from DLL as below.


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    [System.Runtime.Serialization.DataContractAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    public partial class CriteriaElement
    {
         private string dataSourceNameField;
         private string fieldNameField;
         private Operator operatorField;
         private string value1Field;
         private string value2Field;

         /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    [System.Runtime.Serialization.DataMemberAttribute(Order=0)]
    public string DataSourceName
    {
    get { return this.dataSourceNameField;}
    set {this.dataSourceNameField = value;}

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=1)]
    [System.Runtime.Serialization.DataMemberAttribute(Order=1)]
    public string FieldName
    {
    get { return this.fieldNameField; }
    set { this.fieldNameField = value; }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=2)]
    [System.Runtime.Serialization.DataMemberAttribute(Order=2)]
    public Operator Operator
    {
    get { return this.operatorField; }
    set { this.operatorField = value;}
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=3)]
    [System.Runtime.Serialization.DataMemberAttribute(Order=3)]
    public string Value1
    {
    get { return this.value1Field; }
    set { this.value1Field = value; }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=4)]
    [System.Runtime.Serialization.DataMemberAttribute(Order=4)]
    public string Value2
    {
    get { return this.value2Field; }
    set { this.value2Field = value;}


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    [System.Runtime.Serialization.DataContractAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    public enum Operator

    /// <remarks/>
    [System.Runtime.Serialization.EnumMemberAttribute()]
    Equal,

    /// <remarks/>
    [System.Runtime.Serialization.EnumMemberAttribute()]
    NotEqual,
    }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    [System.Runtime.Serialization.DataContractAttribute(Namespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
    public partial class QueryCriteria
    {
    private CriteriaElement[] criteriaElementField;

       /// <remarks/>
       [System.Xml.Serialization.XmlElementAttribute("CriteriaElement", Order=0)]
       [System.Runtime.Serialization.DataMemberAttribute(Name="CriteriaElement",Order=0)]
       public CriteriaElement[] CriteriaElement
           {
             get {   return this.criteriaElementField; }
             set {   this.criteriaElementField = value;}
           }
    }

    Can anyone know, why extra complex element is created by XsdDataContractExporter?

    Thanks,

    Amol Shinde.

    Friday, January 20, 2017 12:26 PM

Answers

  • Hi Amol,

    It is sad that I still could not reproduce your issue. In your previous post, you used “NETFX 4.5.1 Tools>SvcUtil InputData.dll” and now you used dot net framework 4.0.

    I made a test with suvctil.exe in VS 2010.

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>svcutil.exe C:\Users\Admin\Desktop\InputData.dll /dconly

    In my option, you are not able to change XsdDataContractExporter or SVCUTIL.EXE, and both of them works for you. I am not sure the reason that you insist on this issue.

    You could refer below link for source code of XsdDataContractExporter, but you are not able to view details implementation in svcutil.exe.
    https://referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/XsdDataContractExporter.cs,56c564462d974c84

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ashinde2 Friday, January 27, 2017 12:38 PM
    Wednesday, January 25, 2017 8:19 AM

All replies

  • Hi Amol,

    Which tool did you use to view XSD like in your image? I made a test with below contract.

    [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
    
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
    
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }

    XsdDataContractExporter Code.

            static void ExportXSD()
            {
                XsdDataContractExporter exporter = new XsdDataContractExporter();
                if (exporter.CanExport(typeof(CompositeType)))
                {
                    exporter.Export(typeof(CompositeType));
                    Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count);
                    Console.WriteLine();
                    XmlSchemaSet mySchemas = exporter.Schemas;
    
                    XmlQualifiedName XmlNameValue = exporter.GetRootElementName(typeof(CompositeType));
                    string EmployeeNameSpace = XmlNameValue.Namespace;
    
                    foreach (XmlSchema schema in mySchemas.Schemas(EmployeeNameSpace))
                    {
                        schema.Write(Console.Out);
                    }
                }
            }
    
            static void GetXmlElementName()
            {
                XsdDataContractExporter myExporter = new XsdDataContractExporter();
                XmlQualifiedName xmlElementName = myExporter.GetRootElementName(typeof(CompositeType));
                Console.WriteLine("Namespace: {0}", xmlElementName.Namespace);
                Console.WriteLine("Name: {0}", xmlElementName.Name);
                Console.WriteLine("IsEmpty: {0}", xmlElementName.IsEmpty);
            }

    XsdDataContractExporter result

    <?xml version="1.0" encoding="Windows-1252"?>
    <xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/WCFSample" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/WCFSample" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="CompositeType">
        <xs:sequence>
          <xs:element minOccurs="0" name="BoolValue" type="xs:boolean" />
          <xs:element minOccurs="0" name="StringValue" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="CompositeType" nillable="true" type="tns:CompositeType" />
    </xs:schema>

    Svcutil.exe result

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/WCFSample" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/WCFSample" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="SampleService">
        <xs:sequence />
      </xs:complexType>
      <xs:element name="SampleService" nillable="true" type="tns:SampleService" />
      <xs:complexType name="CompositeType">
        <xs:sequence>
          <xs:element minOccurs="0" name="BoolValue" type="xs:boolean" />
          <xs:element minOccurs="0" name="StringValue" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="CompositeType" nillable="true" type="tns:CompositeType" />
    </xs:schema>

    You could find XsdDataContractExporter did not have extra complex element. Instead, Svcutil.exe has one more complexType name="SampleService".

    It would be helpful if you could share us detailed steps which could reproduce your issue like DataContract, command for svcutil.exe and Code for XsdDataContractExporter.

    In my option, the different results might be related with different implementing in XsdDataContractExporter and Svcutil.exe. Did you get any error while you using XsdDataContractExporter or Svcutil.exe?

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, January 23, 2017 3:00 AM
  • Hi Edward Z,

    Thanks for the reply.

    I did not get any error while using XsdDataContractExporter or Svcutil.exe.

    I am using XMLSPY to see generated schema.

    Please find below complete code.

    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        [System.Runtime.Serialization.DataContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        public class CriteriaElement
        {
            private string dataSourceNameField;
    
            private string fieldNameField;
    
            private Operator operatorField;
    
            private string value1Field;
    
            private string value2Field;
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 0)]
            public string DataSourceName
            {
                get
                {
                    return this.dataSourceNameField;
                }
                set
                {
                    this.dataSourceNameField = value;
                }
            }
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 1)]
            public string FieldName
            {
                get
                {
                    return this.fieldNameField;
                }
                set
                {
                    this.fieldNameField = value;
                }
            }
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Order = 2)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 2)]
            public Operator Operator
            {
                get
                {
                    return this.operatorField;
                }
                set
                {
                    this.operatorField = value;
                }
            }
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Order = 3)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 3)]
            public string Value1
            {
                get
                {
                    return this.value1Field;
                }
                set
                {
                    this.value1Field = value;
                }
            }
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute(Order = 4)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 4)]
            public string Value2
            {
                get
                {
                    return this.value2Field;
                }
                set
                {
                    this.value2Field = value;
                }
            }
        }
    
        /// <remarks/>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
        [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        [System.Runtime.Serialization.DataContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        public enum Operator
        {
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            Equal,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            NotEqual,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            Greater,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            GreaterOrEqual,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            Less,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            LessOrEqual,
    
            /// <remarks/>
            [System.Runtime.Serialization.EnumMemberAttribute()]
            Range,
        }
    [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
        [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.ComponentModel.DesignerCategoryAttribute("code")]
        [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        [System.Runtime.Serialization.DataContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
        public class QueryCriteria
        {
            private CriteriaElement[] criteriaElementField;
    
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute("CriteriaElement", Order = 0)]
            [System.Runtime.Serialization.DataMemberAttribute(Name = "CriteriaElement", Order = 0)]
            public CriteriaElement[] CriteriaElement
            {
                get
                {
                    return this.criteriaElementField;
                }
                set
                {
                    this.criteriaElementField = value;
                }
            }
        }
     [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        [System.ServiceModel.MessageContractAttribute(WrapperName = "CustomerServiceFindRequest", WrapperNamespace = "http://schemas.microsoft.com/dynamics/2008/01/services", IsWrapped = true)]
        [System.Runtime.Serialization.DataContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2008/01/services")]
        public  class FindRequest
        {
            [System.ServiceModel.MessageBodyMemberAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria", Order = 0)]
            [System.Runtime.Serialization.DataMemberAttribute(Order = 0)]
            [System.Xml.Serialization.XmlElementAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria")]
            public QueryCriteria QueryCriteria;
    
            public FindRequest()
            {
            }
    
            public FindRequest( QueryCriteria QueryCriteria)
            {
                this.QueryCriteria = QueryCriteria;
            }
        }


     [System.Diagnostics.DebuggerStepThroughAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
        [System.ServiceModel.MessageContractAttribute(WrapperName = "CustomerServiceFindResponse", WrapperNamespace = "http://schemas.microsoft.com/dynamics/2008/01/services", IsWrapped = true)]
        [System.Runtime.Serialization.DataContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2008/01/services")]
        public  class FindResponse
        {
            public FindResponse()
            {
            }
        }


     [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
        [System.ServiceModel.ServiceContractAttribute(Namespace = "http://schemas.microsoft.com/dynamics/2008/01/services", ConfigurationName = "CustomerService")]
        public interface ITestService
        {
            [System.ServiceModel.OperationContractAttribute(Action = "http://schemas.microsoft.com/dynamics/2008/01/services/CustomerService/find", ReplyAction = "http://schemas.microsoft.com/dynamics/2008/01/services/CustomerService/findRespon" +
                "se")]
            [System.ServiceModel.XmlSerializerFormatAttribute()]
            FindResponse find(FindRequest request);
        }

    - Please create DLL by using all above classes, Lets say InputData.DLL.

    - Create one console application and give reference of InputData.DLL.

    - Create class "Program" as below.

    class Program
        {
            static void Main(string[] args)
            {
                XsdDataContractExporter exporter = new XsdDataContractExporter();
                if (exporter.CanExport(typeof(QueryCriteria)))
                {
                    exporter.Export(typeof(QueryCriteria));
                    Console.WriteLine("number of schemas: {0}", exporter.Schemas.Count);
                    Console.WriteLine();
                    XmlSchemaSet mySchemas = exporter.Schemas;
    
                    XmlQualifiedName XmlNameValue = exporter.GetRootElementName(typeof(QueryCriteria));
                    string EmployeeNameSpace = XmlNameValue.Namespace;
    
                    foreach (XmlSchema schema in mySchemas.Schemas(EmployeeNameSpace))
                    {
                        schema.Write(Console.Out);
                    }
                    Console.ReadLine();
                }
            }
        }


    You will get output as below which will creates one additional complex element ArrayOfCriteriaElement.

    <?xml version="1.0" encoding="IBM437"?>
    <xs:schema targetNamespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" elementFormDefault="qualified" xmlns:tns="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    	<xs:complexType name="QueryCriteria">
    		<xs:sequence>
    			<xs:element name="CriteriaElement" type="tns:ArrayOfCriteriaElement" nillable="true" minOccurs="0"/>
    		</xs:sequence>
    	</xs:complexType>
    	<xs:element name="QueryCriteria" type="tns:QueryCriteria" nillable="true"/>
    	<xs:complexType name="ArrayOfCriteriaElement">
    		<xs:sequence>
    			<xs:element name="CriteriaElement" type="tns:CriteriaElement" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
    		</xs:sequence>
    	</xs:complexType>
    	<xs:element name="ArrayOfCriteriaElement" type="tns:ArrayOfCriteriaElement" nillable="true"/>
    	<xs:complexType name="CriteriaElement">
    		<xs:sequence>
    			<xs:element name="DataSourceName" type="xs:string" nillable="true" minOccurs="0"/>
    			<xs:element name="FieldName" type="xs:string" nillable="true" minOccurs="0"/>
    			<xs:element name="Operator" type="tns:Operator" minOccurs="0"/>
    			<xs:element name="Value1" type="xs:string" nillable="true" minOccurs="0"/>
    			<xs:element name="Value2" type="xs:string" nillable="true" minOccurs="0"/>
    		</xs:sequence>
    	</xs:complexType>
    	<xs:element name="CriteriaElement" type="tns:CriteriaElement" nillable="true"/>
    	<xs:simpleType name="Operator">
    		<xs:restriction base="xs:string">
    			<xs:enumeration value="Equal"/>
    			<xs:enumeration value="NotEqual"/>
    			<xs:enumeration value="Greater"/>
    			<xs:enumeration value="GreaterOrEqual"/>
    			<xs:enumeration value="Less"/>
    			<xs:enumeration value="LessOrEqual"/>
    			<xs:enumeration value="Range"/>
    		</xs:restriction>
    	</xs:simpleType>
    	<xs:element name="Operator" type="tns:Operator" nillable="true"/>
    </xs:schema>

    - Now try to create XSD by using svcutil.exe as below

    C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools>SvcUtil InputData.dll

    - By executing above command you will get different schemas. Please see schemas.microsoft.com.dynamics.2006.02.documents.QueryCriteria.xsd which will not create additional complex element.

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema targetNamespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" elementFormDefault="qualified" xmlns:tns="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    	<xs:element name="QueryCriteria" type="tns:QueryCriteria"/>
    	<xs:complexType name="QueryCriteria">
    		<xs:sequence>
    			<xs:element name="CriteriaElement" type="tns:CriteriaElement" minOccurs="0" maxOccurs="unbounded"/>
    		</xs:sequence>
    	</xs:complexType>
    	<xs:complexType name="CriteriaElement">
    		<xs:sequence>
    			<xs:element name="DataSourceName" type="xs:string" minOccurs="0"/>
    			<xs:element name="FieldName" type="xs:string" minOccurs="0"/>
    			<xs:element name="Operator" type="tns:Operator"/>
    			<xs:element name="Value1" type="xs:string" minOccurs="0"/>
    			<xs:element name="Value2" type="xs:string" minOccurs="0"/>
    		</xs:sequence>
    	</xs:complexType>
    	<xs:simpleType name="Operator">
    		<xs:restriction base="xs:string">
    			<xs:enumeration value="Equal"/>
    			<xs:enumeration value="NotEqual"/>
    			<xs:enumeration value="Greater"/>
    			<xs:enumeration value="GreaterOrEqual"/>
    			<xs:enumeration value="Less"/>
    			<xs:enumeration value="LessOrEqual"/>
    			<xs:enumeration value="Range"/>
    		</xs:restriction>
    	</xs:simpleType>
    </xs:schema>

    My question was why this ArrayOfCriteriaElement creates in XsdDataContractExporter and not in SVCutil.exe

    Thanks,

    Amol Shinde.




    • Edited by ashinde2 Monday, January 23, 2017 7:31 AM
    Monday, January 23, 2017 7:25 AM
  • Hi Amol,

    Thanks for sharing more detailed information. But, I failed to reproduce your issue. Output files for XsdDataContractExporter and SVCUTIL.EXE are the same except the position of <xs:complexType name="ArrayOfCriteriaElement">.

    Here are the output results.

    XsdDataContractExporter

    <?xml version="1.0" encoding="Windows-1252"?>
    <xs:schema xmlns:tns="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="QueryCriteria">
        <xs:sequence>
          <xs:element minOccurs="0" name="CriteriaElement" nillable="true" type="tns:ArrayOfCriteriaElement" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="QueryCriteria" nillable="true" type="tns:QueryCriteria" />
      <xs:complexType name="ArrayOfCriteriaElement">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="unbounded" name="CriteriaElement" nillable="true" type="tns:CriteriaElement" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="ArrayOfCriteriaElement" nillable="true" type="tns:ArrayOfCriteriaElement" />
      <xs:complexType name="CriteriaElement">
        <xs:sequence>
          <xs:element minOccurs="0" name="DataSourceName" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="FieldName" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="Operator" type="tns:Operator" />
          <xs:element minOccurs="0" name="Value1" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="Value2" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="CriteriaElement" nillable="true" type="tns:CriteriaElement" />
      <xs:simpleType name="Operator">
        <xs:restriction base="xs:string">
          <xs:enumeration value="Equal" />
          <xs:enumeration value="NotEqual" />
          <xs:enumeration value="Greater" />
          <xs:enumeration value="GreaterOrEqual" />
          <xs:enumeration value="Less" />
          <xs:enumeration value="LessOrEqual" />
          <xs:enumeration value="Range" />
        </xs:restriction>
      </xs:simpleType>
      <xs:element name="Operator" nillable="true" type="tns:Operator" />
    </xs:schema>

    Svcutil.exe

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:tns="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:complexType name="CriteriaElement">
        <xs:sequence>
          <xs:element minOccurs="0" name="DataSourceName" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="FieldName" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="Operator" type="tns:Operator" />
          <xs:element minOccurs="0" name="Value1" nillable="true" type="xs:string" />
          <xs:element minOccurs="0" name="Value2" nillable="true" type="xs:string" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="CriteriaElement" nillable="true" type="tns:CriteriaElement" />
      <xs:simpleType name="Operator">
        <xs:restriction base="xs:string">
          <xs:enumeration value="Equal" />
          <xs:enumeration value="NotEqual" />
          <xs:enumeration value="Greater" />
          <xs:enumeration value="GreaterOrEqual" />
          <xs:enumeration value="Less" />
          <xs:enumeration value="LessOrEqual" />
          <xs:enumeration value="Range" />
        </xs:restriction>
      </xs:simpleType>
      <xs:element name="Operator" nillable="true" type="tns:Operator" />
      <xs:complexType name="QueryCriteria">
        <xs:sequence>
          <xs:element minOccurs="0" name="CriteriaElement" nillable="true" type="tns:ArrayOfCriteriaElement" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="QueryCriteria" nillable="true" type="tns:QueryCriteria" />
      <xs:complexType name="ArrayOfCriteriaElement">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="unbounded" name="CriteriaElement" nillable="true" type="tns:CriteriaElement" />
        </xs:sequence>
      </xs:complexType>
      <xs:element name="ArrayOfCriteriaElement" nillable="true" type="tns:ArrayOfCriteriaElement" />
    </xs:schema>

    Not sure whether it is related with XMSPY, I suggest you try to save the output files after you get from XsdDataContractExporter and SVCUTIL.EXE, and check the difference by using file comparing tools.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 24, 2017 8:04 AM
  • Hi Edward,

    Thanks for the reply.

    I can reproduce the issue where XsdDataContractExporter creates extra complex field ArrayOfCriteriaElement in XSD as compare to Svcutil.exe.

    I am reproducing the issue on Visual studio 2010 with dot net framework 4.0, SVCutil.exe also has the same dot net framework.

    The problem is not related to XMLSPY, I am saving both XSD i.e from XsdDataContractExporter and SVCUTIL.EXE to local disk and then opening it to XMLSPY/ Notepad++.

    Thanks and Regards,

    Amol Shinde.


    Wednesday, January 25, 2017 5:28 AM
  • Hi Amol,

    It is sad that I still could not reproduce your issue. In your previous post, you used “NETFX 4.5.1 Tools>SvcUtil InputData.dll” and now you used dot net framework 4.0.

    I made a test with suvctil.exe in VS 2010.

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>svcutil.exe C:\Users\Admin\Desktop\InputData.dll /dconly

    In my option, you are not able to change XsdDataContractExporter or SVCUTIL.EXE, and both of them works for you. I am not sure the reason that you insist on this issue.

    You could refer below link for source code of XsdDataContractExporter, but you are not able to view details implementation in svcutil.exe.
    https://referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/XsdDataContractExporter.cs,56c564462d974c84

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ashinde2 Friday, January 27, 2017 12:38 PM
    Wednesday, January 25, 2017 8:19 AM
  • Hi Edward,

    I got the root cause of problem.

    I was comparing result of XsdDataContractExporter with C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools>SvcUtil InputData.dll, which was wrong.

    I should compare result of XsdDataContractExporter with C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools>SvcUtil InputData.dll /dconly, which gave same results.

    Thanks a lot.

    Amol Shinde.


    Friday, January 27, 2017 12:38 PM