当前位置 : 主页 > 网页制作 > xml >

如何让ServiceStack从带有XML命名空间的TFS接收XML请求

来源:互联网 收集:自由互联 发布时间:2021-06-13
我正在尝试将TFS 2012事件通知连接到ServiceStack,但我只是不断收到错误: { "responseStatus": { "errorCode": "RequestBindingException", "message": "Unable to bind request", "stackTrace": "at ServiceStack.WebHost.Endpoint
我正在尝试将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 deserializing only works with namespace in xml

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

>将DataContract属性的Name属性设置为BuildStatusChangeEvent.它控制顶级XML元素的预期名称.否则,ServiceStack将期望XML看起来像< TfsEventBuildComplete>< BuildUri> …
>将DataContract属性的Namespace属性设置为空字符串,以便请求中不需要特定的xmlns属性
>设置DataMember属性的Order属性,以指定XML元素在从TFS获取的XML中的排序顺序.默认情况下,XML序列化程序将期望元素排序为alphabetically,因此您必须覆盖此属性,否则某些部分属性将无法正确反序列化

[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; }
}
网友评论