WorkItemChangedEvent和AddedRelations字段

时间:2010-08-31 13:05:32

标签: api tfs

我试图通过TFS服务捕获WorkItemChangedEvent来捕获添加到TFS中的工作项的链接。以下是消息的相关XML部分:

<AddedRelations><AddedRelation><WorkItemId>8846</WorkItemId></AddedRelation></AddedRelations>

这被声明为WorkItemChangedEvent类中的一个字段,应该在收到事件后反序列化为对象:

public partial class WorkItemChangedEvent
{
    private string[] addedRelations;
    /// <remarks/>
    [XmlArrayItemAttribute("WorkItemId", IsNullable = false)]
    public string[] AddedRelations
    {
        get { return this.addedRelations; }
        set { this.addedRelations = value; }
    }
}

我无法弄清楚为什么AddedRelations无法正确反序列化。

我只能怀疑对象结构与XML架构不匹配。

1 个答案:

答案 0 :(得分:1)

我稍微更改了WorkItemChangedEvent类的结构以匹配XML:

public partial class WorkItemChangedEvent
{
private AddedRelation[] addedRelations;

/// <remarks/>
    [XmlArrayItemAttribute("AddedRelation", IsNullable = false)]
    public AddedRelation[] AddedRelations
    {
        get { return this.addedRelations; }
        set { this.addedRelations = value; }
    }

[GeneratedCodeAttribute("xsd", "2.0.50727.42")]
    [SerializableAttribute()]
    [DebuggerStepThroughAttribute()]
    [DesignerCategoryAttribute("code")]
    [XmlTypeAttribute(Namespace = "")]
    public partial class AddedRelation
    {
        #region Fields
        private string workItemId;
        #endregion

        /// <remarks/>
        public string WorkItemId
        {
            get { return this.workItemId; }
            set { this.workItemId = value; }
        }
    }
}

我仍然认为原始解决方案必须有一些逻辑,因为它是由TFS作者(MS)设计的?无论如何,我很高兴它现在有效,我先回答了我的问题;]