【问题标题】:WCF Return Data is Missing Data When Subclassing a List<T>子类化 List<T> 时 WCF 返回数据缺少数据
【发布时间】:2011-03-14 16:06:39
【问题描述】:

我在我的客户端和服务器之间共享合同(不使用生成的代理)。这是合同(注意我也尝试过 ObservableCollection):

public class MyList : List<MyItem> {
    public int Total { get; set; }
    public MyList() { }
}

在服务器上调用 EndMyOperation 异步回调方法时仍会设置 Total。但是,当我查看客户端上的值时,Total 消失了(设置为 0)。跟踪清楚地表明附加属性没有被传递。谁能解释一下为什么会这样?

<MessageLogTraceRecord>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/MyOperation</Action>
    <ActivityId CorrelationId="d2872ac2-685e-4f94-b516-aaba4effa463" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">695d611f-2b3d-48ca-80b8-7ceae4fd423f</ActivityId>
    </s:Header>
    <s:Body>
      <MyOperationResponse xmlns="http://tempuri.org/">
        <MyOperationResult xmlns:d4p1="http://schemas.datacontract.org/2004/07/MyDataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <d4p1:MyItem>
            <d4p1:MyId>1</d4p1:MyId>
          </d4p1:MyItem>
          <d4p1:MyItem>
            <d4p1:MyId>12</d4p1:MyId>
          </d4p1:MyItem>
        </MyOperationResult>
      </MyOperationResponse>
    </s:Body>
  </s:Envelope>
</MessageLogTraceRecord>

只是为了澄清一下,我知道我可以通过不子类化并执行以下操作来解决问题。相反,我试图理解为什么会发生上述行为。

public class MyPagedList<T> { 
    public int Total { get; set; } 
    public List<T> MyList { get; set; }
    public MyPagedList() { MyList = new List<T>(); }
}

【问题讨论】:

  • 你能发布实际的数据合同吗?您是否将 DataMember 属性正确放置在您希望序列化的属性之上?
  • @MattC - MyList 类是数据契约。无需在代码上放置属性。

标签: wcf collections return-value subclass message


【解决方案1】:

MyItem[Serializable]?或者更确切地说,MyItem 上的字段是否可序列化?

或者这可能是你的问题:inheriting-generic-collection-and-serialization

【讨论】:

  • 没有明确标记,但是它们是可序列化的。您的链接正是我想要的。谢谢。
猜你喜欢
  • 2010-12-13
  • 1970-01-01
  • 2013-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-09-27
  • 1970-01-01
  • 2019-02-08
  • 1970-01-01
相关资源
最近更新 更多