我已經使用xsd.exe工具產生一組基於一組各自* xsd文件的類,如下所示:WCF SerializableAttribute DataContractAttribute XmlTypeAttribute 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?
如果要生成數據協定,請不要使用xsd.exe。這是舊的XML Serializer技術的一部分。改用svcutil.exe。 –
謝謝!是否有任何理由使用svcutil.exe。 xsd.exe會被棄用嗎?或將svcutilexe更好的WCF? – Pingpong
svcutil.exe適用於WCF。只是不要使用xsd.exe。 「已棄用」是一個法律術語,但「不使用它」是事實。 –