我正在尝试使用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&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><?xml version="1.0" encoding="utf-16"?><BuildCompletionEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><BuildUri>vstfs:///Build/Build/4818</BuildUri><TeamFoundationServerUrl>http://tfsdomain:8080/tfs/02</TeamFoundationServerUrl><TeamProject>projectname</TeamProject><Id>Test_20130815.10</Id><Url>http://tfsdomain:8080/tfs/web/build.aspx?pcguid=88661c27-0916-48cb-8e39-9b40d8beb457&amp;builduri=vstfs:///Build/Build/4818</Url><Title>Build Test_20130815.10 Successfully Completed</Title><CompletionStatus>Successfully Completed</CompletionStatus><Subscriber>TFSSERVICE</Subscriber><Configuration>Test</Configuration><RequestedBy>domain\\username</RequestedBy><TimeZone>GMT Daylight Time</TimeZone><TimeZoneOffset>+01:00:00</TimeZoneOffset><BuildStartTime>8/15/2013 3:38:48 PM</BuildStartTime><BuildCompleteTime>8/15/2013 3:39:11 PM</BuildCompleteTime><BuildMachine>Master - Controller</BuildMachine></BuildCompletionEvent></eventXml>
<tfsIdentityXml><TeamFoundationServer url="http://isams-tfs2012:8080/tfs/02/Services/v3.0/LocationService.asmx" /></tfsIdentityXml>
<SubscriptionInfo>
<Classification><PT N="management.domain.co.uk - Release build subscription." /></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
答案 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
之前,它才开始工作。