Results 1 to 2 of 2

Thread: [RESOLVED] VS2010: Service xml serialization - xsd schema output

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved [RESOLVED] VS2010: Service xml serialization - xsd schema output

    Hi,

    I've created a WCF web service and generated the xml serialization class with xsd.exe. My problem is that when I request the xsd from the service (http://localhost:59120/Service1.svc?xsd=xsd2) the element names are appended with "Field" does anyone know how to override these default names with the original element names?

    Code:
    <xs:sequence>
      <xs:element name="addressField" type="xs:string" nillable="true"/>
      <xs:element name="emailIdField" type="xs:string" nillable="true"/>
      <xs:element name="idField" type="xs:string" nillable="true"/>
      <xs:element name="itemsField" type="tns:ArrayOfArrayOfOrdersCustomerItemsItem" nillable="true"/>
      <xs:element name="nameField" type="xs:string" nillable="true"/>
     </xs:sequence>

    c# Code:
    1. //------------------------------------------------------------------------------
    2. // <auto-generated>
    3. //     This code was generated by a tool.
    4. //     Runtime Version:4.0.30319.296
    5. //
    6. //     Changes to this file may cause incorrect behavior and will be lost if
    7. //     the code is regenerated.
    8. // </auto-generated>
    9. //------------------------------------------------------------------------------
    10.  
    11. //
    12. // This source code was auto-generated by xsd, Version=4.0.30319.1.
    13. //
    14. namespace WcfService1 {
    15.     using System.Xml.Serialization;
    16.    
    17.    
    18.     /// <remarks/>
    19.     [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    20.     [System.SerializableAttribute()]
    21.     [System.Diagnostics.DebuggerStepThroughAttribute()]
    22.     [System.ComponentModel.DesignerCategoryAttribute("code")]
    23.     [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    24.     [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    25.     public partial class Orders {
    26.        
    27.         private OrdersCustomer[] itemsField;
    28.        
    29.         /// <remarks/>
    30.         [System.Xml.Serialization.XmlElementAttribute("Customer", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    31.         public OrdersCustomer[] Items {
    32.             get {
    33.                 return this.itemsField;
    34.             }
    35.             set {
    36.                 this.itemsField = value;
    37.             }
    38.         }
    39.     }
    40.    
    41.     /// <remarks/>
    42.     [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    43.     [System.SerializableAttribute()]
    44.     [System.Diagnostics.DebuggerStepThroughAttribute()]
    45.     [System.ComponentModel.DesignerCategoryAttribute("code")]
    46.     [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    47.     public partial class OrdersCustomer {
    48.        
    49.         private string nameField;
    50.        
    51.         private string addressField;
    52.        
    53.         private string emailIdField;
    54.        
    55.         private OrdersCustomerItemsItem[][] itemsField;
    56.        
    57.         private string idField;
    58.        
    59.         /// <remarks/>
    60.         [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    61.         public string Name {
    62.             get {
    63.                 return this.nameField;
    64.             }
    65.             set {
    66.                 this.nameField = value;
    67.             }
    68.         }
    69.        
    70.         /// <remarks/>
    71.         [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
    72.         public string Address {
    73.             get {
    74.                 return this.addressField;
    75.             }
    76.             set {
    77.                 this.addressField = value;
    78.             }
    79.         }
    80.        
    81.         /// <remarks/>
    82.         [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
    83.         public string EmailId {
    84.             get {
    85.                 return this.emailIdField;
    86.             }
    87.             set {
    88.                 this.emailIdField = value;
    89.             }
    90.         }
    91.        
    92.         /// <remarks/>
    93.         [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=3)]
    94.         [System.Xml.Serialization.XmlArrayItemAttribute("Item", typeof(OrdersCustomerItemsItem), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    95.         public OrdersCustomerItemsItem[][] Items {
    96.             get {
    97.                 return this.itemsField;
    98.             }
    99.             set {
    100.                 this.itemsField = value;
    101.             }
    102.         }
    103.        
    104.         /// <remarks/>
    105.         [System.Xml.Serialization.XmlAttributeAttribute()]
    106.         public string Id {
    107.             get {
    108.                 return this.idField;
    109.             }
    110.             set {
    111.                 this.idField = value;
    112.             }
    113.         }
    114.     }
    115.    
    116.     /// <remarks/>
    117.     [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    118.     [System.SerializableAttribute()]
    119.     [System.Diagnostics.DebuggerStepThroughAttribute()]
    120.     [System.ComponentModel.DesignerCategoryAttribute("code")]
    121.     [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    122.     public partial class OrdersCustomerItemsItem {
    123.        
    124.         private string idField;
    125.        
    126.         private string nameField;
    127.        
    128.         /// <remarks/>
    129.         [System.Xml.Serialization.XmlAttributeAttribute()]
    130.         public string Id {
    131.             get {
    132.                 return this.idField;
    133.             }
    134.             set {
    135.                 this.idField = value;
    136.             }
    137.         }
    138.        
    139.         /// <remarks/>
    140.         [System.Xml.Serialization.XmlAttributeAttribute()]
    141.         public string Name {
    142.             get {
    143.                 return this.nameField;
    144.             }
    145.             set {
    146.                 this.nameField = value;
    147.             }
    148.         }
    149.     }
    150. }

    Regards Al

  2. #2

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Re: VS2010: Service xml serialization - xsd schema output

    Hi,

    I've managed to fix this by regenerating my class (xsd.exe) using the f switch "/f[ields]" which generates fields instead of properties. By default, properties are generated.


    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx

    Source: http://forums.asp.net/p/1867094/5245...15760042769749

    I have a second problem but will create a new thread for it.
    Last edited by aconybeare; Dec 20th, 2012 at 05:02 AM. Reason: Fixed link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width