我有一個WCF客戶端,它向WCF服務發送請求。客戶端和服務器都在本地運行。請求由DateTime類型值組成,該值具有一個值(例如DateTime.Now)。 WCF客戶端代理髮送請求。但是,在將請求發送到服務器之前,使用fiddler捕獲請求時,DateTime類型的所有值都會消失。發送請求到WCF服務器時,DateTime類型值消失
更新:
我手動嘗試都DataContractSerializer的和的XmlSerializer到串行器WCF類(如下所示),其結果是,XmlSerializer的省略了日期時間值(即,DateTime值消失),DataContractSerializer的保持值。
因爲WCF服務器正在使用XmlSerializer,並且由於客戶端代理類的數量,理想情況下,客戶端應該使用XmlSerializer。
WCF客戶端:
WCF代理類:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
//[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:core_e-nbp-v1.0")]
public partial class ClaimApplication : object, System.ComponentModel.INotifyPropertyChanged {
private System.DateTime hBEffectiveDateField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(DataType = "date", Order = 3)]
public System.DateTime HBEffectiveDate {
get {
return this.hBEffectiveDateField;
}
set {
this.hBEffectiveDateField = value;
this.RaisePropertyChanged("HBEffectiveDate");
}
}
}
//Assign a random DateTime value
claimApplication.HBEffectiveDate = DateTime.Now.ToUniversalTime();
//manully serialize to check the DateTime using XmlSerializer
XmlSerializer s = new XmlSerializer(typeof(ClaimApplication));
StreamWriter sw = new StreamWriter(@"D:\xmlsamples\XmlSerializer.xml");
s.Serialize(sw,claimApplication);
sw.Dispose();
//manully serialize to check the DateTime using DataContractSerializer
DataContractSerializer dc = new DataContractSerializer(typeof(ClaimApplication));
FileStream fs = new FileStream(@"D:\xmlsamples\DataContractSerializer.xml", FileMode.CreateNew);
dc.WriteObject(fs,claimApplication);
fs.Dispose();
WCF服務器:
[System.Xml.Serialization.XmlElementAttribute(DataType = "date")]
public System.DateTime EffectiveDate
{
get { return this.EffectiveDateField; }
set { this.EffectiveDateField = value; }
}
任何想法?