4

我正在尝试将 TFS 2012 事件通知连接到 ServiceStack,但我不断收到错误消息:

{
    "responseStatus": {
        "errorCode": "RequestBindingException",
        "message": "Unable to bind request",
        "stackTrace": "at ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath)\r\n   
                       at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest (IHttpRequest httpReq, IHttpResponse httpRes, String operationName)"
    }
}

这是我的 DTO(它包含一些我试图让它工作的位)。

[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
[DataContract(Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public class TfsEventBuildComplete : IReturn<BuildCompleteResponse>
{
    [DataMember]
    public string BuildUri { get; set; }

    [DataMember]
    public string TeamFoundationServerUrl { get; set; }

    [DataMember]
    public string TeamProject { get; set; }

    [DataMember]
    public string Title { get; set; }

    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public TfsEventStatusChange StatusChange { get; set; }

    [DataMember]
    public string ChangedBy { get; set; }
}

public class TfsEventStatusChange
{
    public string FieldName { get; set; }

    public string NewValue { get; set; }
}

以下是来自 TFS 的 XML:

<BuildStatusChangeEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <BuildUri>vstfs:///Build/Build/4799</BuildUri>
    <TeamFoundationServerUrl>http://TFSURL:8080/tfs/collection</TeamFoundationServerUrl>
    <TeamProject>iSAMS</TeamProject>
    <Title>iSAMS Build Release_20130814.1 Quality Changed To Publish</Title>
    <Subscriber>[02]\Project Collection Service Accounts</Subscriber>
    <Id>Release_20130814.1</Id>
    <Url>http://TFSURL:8080/tfs/web/build.aspx?pcguid=GUID&amp;builduri=vstfs:///Build/Build/4799</Url>
    <TimeZone>GMT Daylight Time</TimeZone>
    <TimeZoneOffset>+01:00:00</TimeZoneOffset>
    <ChangedTime>8/14/2013 9:33:30 AM</ChangedTime>
    <StatusChange>
        <FieldName>Quality</FieldName>
        <NewValue>Publish</NewValue>
    </StatusChange>
    <ChangedBy>DOMAIN\USER</ChangedBy>
</BuildStatusChangeEvent>

我认为由于命名空间,ServiceStack 实际上无法反序列化请求,但我无法弄清楚。

我尝试过的大部分内容都来自这里:

XML 反序列化仅适用于 xml 中的命名空间

4

1 回答 1

5

这是我为使示例请求 XML 工作所做的工作:

  1. Name属性的DataContract属性设置为BuildStatusChangeEvent。这控制顶级 XML 元素的预期名称。否则 ServiceStack 将期望 XML 看起来像<TfsEventBuildComplete><BuildUri>...
  2. Namespace属性的DataContract属性设置为空字符串,这样xmlns请求中就不需要特定的属性
  3. 设置Order属性的DataMember属性以指定 XML 元素在您从 TFS 获得的 XML 中的排序顺序。默认情况下,XML 序列化程序将期望元素按字母顺序排序,因此您必须覆盖它,否则您的某些属性将无法正确反序列化
[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
[DataContract(Namespace = "", Name = "BuildStatusChangeEvent")]
public class TfsEventBuildComplete : IReturn<BuildCompleteResponse>
{
    [DataMember(Order=1)]
    public string BuildUri { get; set; }

    [DataMember(Order=2)]
    public string TeamFoundationServerUrl { get; set; }

    [DataMember(Order=3)]
    public string TeamProject { get; set; }

    [DataMember(Order=4)]
    public string Title { get; set; }

    [DataMember(Order=5)]
    public string Id { get; set; }

    [DataMember(Order=6)]
    public TfsEventStatusChange StatusChange { get; set; }

    [DataMember(Order=7)]
    public string ChangedBy { get; set; }
}
于 2013-08-14T15:13:18.617 回答