【发布时间】:2011-10-05 03:58:18
【问题描述】:
我在调试我的新 WCF 服务时遇到了令人沮丧的事情。问题在于某个 DataContract。似乎在某个属性发生后在服务器端进行反序列化,其余部分未设置。我查看了从元数据生成的 xsd 模式,一切似乎都很好。我使用 Fiddler 来监听发送的肥皂数据包,并让客户端所有数据都存在。我什至将 Order 参数设置为 DataContract 属性,以查看我是否可以看到模式但从未看到。我还将 DataMember 名称与消息中的名称进行了比较,它们都匹配。我发现的唯一模式是:
以下是相关 DataContract 对象的 xsd 定义:
<xs:complexType name="Attachment">
<xs:sequence>
<xs:element minOccurs="0" name="dateTime" type="xs:dateTime"/>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="fileName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="guid" type="ser:guid"/>
<xs:element minOccurs="0" name="obsDate" type="xs:dateTime"/>
<xs:element minOccurs="0" name="operation" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="originalFileName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="title" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="type" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
这是 DataContract 对象:
[DataContract(Namespace="http://www.myns.com")]
public class Attachment
{
public enum AttachmentSortOrder { Date, FileType }
[DataMember]
public Guid guid;
[DataMember]
public DateTime dateTime;
[DataMember]
public string operation;
[DataMember]
public DateTime obsDate;
[DataMember]
public string originalFileName;
[DataMember]
public string fileName;
[DataMember]
public string title;
[DataMember]
public string type;
[DataMember]
public string description;
}
似乎 obsDate 之后的所有属性由于某种原因没有设置。
为什么?
【问题讨论】:
-
您能否发布您用于反序列化的 XML(这会导致无法设置属性)?