1

我正在尝试使用 TFS 构建通知来提醒我的 ServiceStack 服务中的端点。TFS 使用 SOAP,我对 SOAP 几乎没有经验。

每当 TFS 到达端点时, my 中的所有属性都为空Request DTO

我的代码如下:

DTO

[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; }
}

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

    public string NewValue { get; set; }
}

我正在订阅BuildCompletionEventTFS 内。如果我将我知道 TFS 正在发送的原始 XML 发送到端点,那么一切正常。但是当它被打包为一个 SOAP 请求时,它就不起作用了。附上 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>

更新

我设法获得了 SOAP 请求,它看起来像这样:

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
    <s:Header xmlns:w="http://www.w3.org/2005/08/addressing">
        <w:Action>http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify</w:Action>
        <w:To>http://192.168.232.51/ErrorReporting.Web/releasemanagement/tfsevents/buildcomplete</w:To>
</s:Header>
<s:Body>
    <Notify xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03">
        <eventXml>&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;BuildCompletionEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;&lt;BuildUri&gt;vstfs:///Build/Build/4818&lt;/BuildUri&gt;&lt;TeamFoundationServerUrl&gt;http://tfsdomain:8080/tfs/02&lt;/TeamFoundationServerUrl&gt;&lt;TeamProject&gt;projectname&lt;/TeamProject&gt;&lt;Id&gt;Test_20130815.10&lt;/Id&gt;&lt;Url&gt;http://tfsdomain:8080/tfs/web/build.aspx?pcguid=88661c27-0916-48cb-8e39-9b40d8beb457&amp;amp;builduri=vstfs:///Build/Build/4818&lt;/Url&gt;&lt;Title&gt;Build Test_20130815.10 Successfully Completed&lt;/Title&gt;&lt;CompletionStatus&gt;Successfully Completed&lt;/CompletionStatus&gt;&lt;Subscriber&gt;TFSSERVICE&lt;/Subscriber&gt;&lt;Configuration&gt;Test&lt;/Configuration&gt;&lt;RequestedBy&gt;domain\\username&lt;/RequestedBy&gt;&lt;TimeZone&gt;GMT Daylight Time&lt;/TimeZone&gt;&lt;TimeZoneOffset&gt;+01:00:00&lt;/TimeZoneOffset&gt;&lt;BuildStartTime&gt;8/15/2013 3:38:48 PM&lt;/BuildStartTime&gt;&lt;BuildCompleteTime&gt;8/15/2013 3:39:11 PM&lt;/BuildCompleteTime&gt;&lt;BuildMachine&gt;Master - Controller&lt;/BuildMachine&gt;&lt;/BuildCompletionEvent&gt;</eventXml>
        <tfsIdentityXml>&lt;TeamFoundationServer url="http://isams-tfs2012:8080/tfs/02/Services/v3.0/LocationService.asmx" /&gt;</tfsIdentityXml>
        <SubscriptionInfo>
            <Classification>&lt;PT N="management.domain.co.uk - Release build subscription." /&gt;</Classification>
            <ID>274</ID>
            <Subscriber>S-1-5-21-3680174039-3422584590-495469403-1397</Subscriber>
        </SubscriptionInfo>
    </Notify>
</s:Body>
</s:Envelope>

我也尝试将我的 DTO 更改为:

[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
[DataContract(Namespace = "", Name = "Notify")]
public class TfsEventBuildCompleteSoap
{
    [DataMember(Order = 1)]
    public string eventXml { get; set; }

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

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

[Serializable]
public class SubscriptionInfo
{
    public string Classification { get; set; }

    public int ID { get; set; }

    public string Subscriber { get; set; }
}

但我仍然没有任何快乐。


更新 2

我还尝试了以下方法:

[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
public class TfsBuildEvent : IRequiresSoapMessage
{
    public Message Message { get; set; }
}

Message也始终为空。

我也尝试过使用Request.GetSoapMessage(),但这给出了错误:

given key was not present in the dictionary

4

1 回答 1

3

我终于得到了这个工作。

我的最终设置如下:

DTO

[Route("/releasemanagement/tfsevents/buildcomplete", "POST")]
[DataContract(Namespace = "http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03", Name = "Notify")]
public class Notify : IReturn<BuildCompleteResponse>
{
    [DataMember(Order = 1)]
    public string eventXml { get; set; }

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

我还将我的请求发布到了错误的 URL。我将它发布到Route属性中定义的 URL。但我应该一直在发帖/soap12

重要的

类名必须与肥皂正文中的开始元素名称相匹配。Nameon 属性DataContract不会为您执行此操作。我原来的类名是TfsEventBuildCompleteSoap,但直到我重命名类时它才开始工作Notify

这篇博文更详细地解释了它

于 2013-08-15T16:17:00.273 回答