1

I have generated a set of classes based on a set of respective *.xsd files using xsd.exe tool, as below:

xsd /c file1.xsd File2.xsd 

One of the generated classes is shown below:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]

[System.SerializableAttribute()]   //please note here

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]

//please note here
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.xx.com/xx")]

public partial class SelfEmploymentTypePartner
{

    private string nameField;

    private SelfEmploymentTypePartnerAddress addressField;

    /// <remarks/>
    public string Name
    {
        get { return this.nameField; }
        set { this.nameField = value; }
    }

    /// <remarks/>
    public SelfEmploymentTypePartnerAddress Address
    {
        get { return this.addressField; }
        set { this.addressField = value; }
    }
}

I want to use all generated classes for WCF, do I need to add DataContractAttribute, and DataMemeberAttribute to the class and its members? as below:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.1432")]

[System.SerializableAttribute()]    //please note here

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]

   //please note here
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, 
Namespace ="urn:corexx:Application")]

[DataContract(Name = "SelfEmploymentTypePartner")]  //please note here

public partial class SelfEmploymentTypePartner
{

    private string nameField;

    private SelfEmploymentTypePartnerAddress addressField;

    /// <remarks/>
    [DataMember]
    public string Name
    {
        get
        {
            return this.nameField;
        }
        set
        {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [DataMember]
    public SelfEmploymentTypePartnerAddress Address
    {
        get
        {
            return this.addressField;
        }
        set
        {
            this.addressField = value;
        }
    }
}

Because the existing live version is using the version 1, If I change it to version 2, will that break the current users?

If I do need to, is there a easy way to do that. Because I have more than thousands of line of codes to edit.

The interface is below:

 [ServiceContract(SessionMode = SessionMode.Allowed, Namespace = "http://www.xxx.com" ,ProtectionLevel=ProtectionLevel.None)]
    [WsdlDocumentation("")]
    public interface IService
    {

        [OperationContract(ProtectionLevel= ProtectionLevel.None)]   //please note here
        [XmlSerializerFormat]   //please note here
        [FaultContract(typeof(ErrorDetailsStructure))]
        MyResponse GetInfo(RequestParameter parameter);

    }

When both OperationContract and XmlSerializerFormat are used for the interface, which one will be used.. Does WCF use XmlSerializer instead of DataContractSerializer?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Pingpong
  • 7,681
  • 21
  • 83
  • 209
  • Don't use xsd.exe if you want to generate data contracts. That's part of the old XML Serializer technology. Use svcutil.exe instead. – John Saunders Dec 06 '11 at 19:52
  • Thanks! Is there any good reason to use svcutil.exe instead. Will xsd.exe be deprecated? or will svcutilexe be better for WCF? – Pingpong Dec 06 '11 at 22:27
  • 1
    svcutil.exe is for WCF. Simply don't use xsd.exe. "deprecated" is a legal term, but "don't use it" is the truth. – John Saunders Dec 06 '11 at 22:31
  • Thank you very much! I wonder if you can have a look at the link regarding how to use svcutil.exe. http://stackoverflow.com/questions/8407889/svcutil-exe-generate-classes-from-xsd-files-for-use-with-wcf – Pingpong Dec 06 '11 at 22:38

1 Answers1

1

You don't need to change the generated code. You only need to tell WCF you are using a different serializer in your service contract definition:

[ServiceContract]
[XmlSerializerFormat]
public interface MyService
{
    [OperationContract]
    [XmlSerializerFormat]
    void MyMethod();
}

However, you should read the pro's and con's of using DataContractSerializer vs XmlSerializer.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • As far as I've experienced this attribute is needed either on a type or on a method, but redundant on both. – tsemer Sep 24 '13 at 13:01