How to get ServiceStack to receive an XML request from TFS with XML namespaces

I am trying to connect TFS 2012 event notifications to ServiceStack, but I just keep getting the error:

{ "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)" } } 

Here is my DTO (It contains some bits that I tried to make it work).

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

Here is the XML that comes from TFS:

 <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> 

I think that ServiceStack does not actually deserialize the request due to the namespace, but I cannot figure it out.

Most of what I tried came from here:

XML deserialization only works with namespace in xml

+4
source share
1 answer

Here is what I did to get an XML sample XML request:

  • Set the Name property of your DataContract attribute to BuildStatusChangeEvent . This controls the expected name of the top-level XML element. Otherwise, the ServiceStack expects the XML to look like <TfsEventBuildComplete><BuildUri>...
  • Set the Namespace property of your DataContract attribute to an empty string so that the request does not require special xmlns attributes
  • Set the Order property of your DataMember attributes to indicate the order in which the XML elements are sorted into the XML that you receive from TFS. By default, the XML serializer expects the elements to be sorted alphabetically , so you must override this, or some of your properties will not be deserialized correctly
 [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; } } 
+5
source

Source: https://habr.com/ru/post/1497026/


All Articles