并非所有属性都在WCF调用中发送或接收

时间:2011-10-05 03:58:18

标签: c# .net wcf

我在调试新的WCF服务时遇到了令人沮丧的困难。问题出在某个DataContract上。看起来像某个属性发生后服务器端的反序列化,其余的都没有设置。我已经查看了从元数据生成的生成的xsd模式,一切似乎都没问题。我使用Fiddler监听发送的soap数据包,并留下客户端所有数据都存在。我甚至将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因某种原因没有设置后的所有属性。

为什么?

2 个答案:

答案 0 :(得分:2)

启用WCF错误记录并通过SvcTraceViewer.exe

找出根本原因

答案 1 :(得分:2)

有助于查看SOAP并了解客户端是否为.NET。

我已经看到使用非.NET客户端发生这样的事情。您的xsd指定sequence - 使用Order属性确定或默认为字母顺序。有些客户似乎将此视为all元素;他们似乎认为“它是完全相同的XML”(见In XML, is order important?)。

总而言之,检查SOAP元素是否与您的XSD匹配正确。