如何让ServiceStack接收SOAP请求?

时间:2013-08-15 08:27:10

标签: soap tfs servicestack tfs-events

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

每当TFS命中端点时,我的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; }
}

我订阅了TFS中的BuildCompletionEvent。如果我发送我知道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

1 个答案:

答案 0 :(得分: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; }
}

我还将我的请求发布到了错误的网址。我将其发布到Route属性中定义的URL。但我总是发帖到/soap12

重要

需要类名来匹配soap正文中的开头元素名称。 Name上的DataContract属性不会为您执行此操作。我的原始班级名称为TfsEventBuildCompleteSoap,但在我重命名班级Notify之前,它才开始工作。

This blog post explains it in more detail