Инструмент WCF SerializableAttribute DataContractAttribute XmlTypeAttribute xsd.exe - PullRequest
1 голос
/ 06 декабря 2011

Я сгенерировал набор классов на основе набора соответствующих файлов * .xsd с помощью инструмента xsd.exe, как показано ниже:

xsd /c file1.xsd File2.xsd 

Один из сгенерированных классов показан ниже:

[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; }
    }
}

Я хочу использовать все сгенерированные классы для WCF, мне нужно добавить DataContractAttribute и DataMemeberAttribute к классу и его членам? как показано ниже:

[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;
        }
    }
}

Поскольку существующая живая версия использует версию 1, если я изменю ее на версию 2, сломает ли это текущих пользователей ?

Если мне нужно, есть простой способ сделать это. Потому что у меня есть более тысячи строк кода для редактирования.

Интерфейс ниже:

 [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);

    }

Если для интерфейса используются и OperationContract, и XmlSerializerFormat, , какой из них будет использоваться. . Использует ли WCF XmlSerializer вместо DataContractSerializer?

1 Ответ

1 голос
/ 06 декабря 2011

Вам не нужно менять сгенерированный код. Вам нужно только указать WCF, что вы используете другой сериализатор в определении вашего контракта на обслуживание:

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

Тем не менее, вы должны ознакомиться с за и против использования DataContractSerializer против XmlSerializer.

...