Web api object is null when using data contract with a xml namespace



I'm trying to integrate legacy API calls into a new web API project. The old calls all used data contracts with data members. I think I have everything matched up but my objects always come in null. If I remove the namespace from the calls when I try it in fiddler it works. However, I can't modify the calls coming in.


Here is the controller code. In this code projectTaskImportBatch comes in as null.



[HttpPost]
[Route("ProjectTaskImportBatch")]
public IHttpActionResult BatchImportXltProjectTask(ProjectTaskImportBatch projectTaskImportBatch)
{
try
{
var xltProjectTaks = XltProjectCore.BatchImportXltProjectTask(projectTaskImportBatch, Token);
return Ok(xltProjectTaks);
}
catch (Exception ex)
{
throw ExceptionHandler.ResponseException(Request, ex);
}
}


And this is the object I'm attempting to populate.



[DataContract(Namespace = "http://col4.com/api/v2", Name = "ProjectTaskImportBatch")]
public class ProjectTaskImportBatch
{
[DataMember(Order = 1)]
public string ProjectID { get; set; }
[DataMember(Order = 2)]
public string Tasks { get; set; }
[DataMember(Order = 3)]
public Int16 LastBatch { get; set; }
}


This is the call I'm making from Fiddler. If I remove xmlns="http://col4.com/api/v2" the code works. However that is not an option.



POST http://localhost: HTTP/1.1
Accept: */*
Content-Type: application/xml;
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; InfoPath.3)
Host: localhost:
Content-Length: 261
Connection: Keep-Alive
Pragma: no-cache
Authorization:

<ProjectTaskImportBatch xmlns:i="http://ift.tt/ra1lAU" xmlns="http://col4.com/api/v2">
<ProjectID>(Project ID here)</ProjectID>
<Tasks>1|Testing Namespace||||||||||</Tasks>
<LastBatch>1</LastBatch>
</ProjectTaskImportBatch>

No comments:

Post a Comment