I'm attempting to manually send some XML content to an ASP MVC Web Api server that I've created. The Controller.Put() method looks like this:
public Game Put(int id, [FromBody] HttpAction[] actions)
{
Debug.WriteLine(actions[0].TargetId + ", " + actions[0].Type + ", " + actions[0].ContentType + ", " + actions[0].Contents);
Game game = this.provider.Update(id, actions);
return game;
}
The null reference occurs immediately when checking the parameters on the action object. This method receives an object Id and an array of type HttpAction which looks like this:
[DataContract]
public class HttpAction
{
[DataMember]
public int TargetId { get; set; }
[DataMember]
public HttpActionType Type { get; set; }
[DataMember]
public HttpActionContentType ContentType { get; set; }
[DataMember]
public string Contents { get; set; }
}
I've setup my PUT request like this:
Header
- Content-Type: application/xml
- Accept: */*
- Accept-Encoding: gzip, deflate, sdch
- Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
(most of the above is generated by Advanced Rest Client which I am using to send the request)
Body
<?xml version="1.0" encoding="utf-8"?>
<HttpActions>
<HttpAction>
<TargetId>0</TargetId>
<Type>Add</Type>
<ContentType>Player</ContentType>
<Contents>UnityPlayer</Contents>
</HttpAction>
</HttpActions>
Another attempt at the body:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfHttpAction xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<HttpAction>
<TargetId xmlns="http://schemas.datacontract.org/2004/07/GOHCGLibrary.Actions">0</TargetId>
<Type xmlns="http://schemas.datacontract.org/2004/07/GOHCGLibrary.Actions">Add</Type>
<ContentType xmlns="http://schemas.datacontract.org/2004/07/GOHCGLibrary.Actions">Player</ContentType>
<Contents xmlns="http://schemas.datacontract.org/2004/07/GOHCGLibrary.Actions">UnityPlayer</Contents>
</HttpAction>
</ArrayOfHttpAction>
Whenever I send this request I find that the body of the request is null in the controller. I've managed to test it while using JSON body and it works fine, I also have unit tests on my controller that pass in HttpAction arrays to check all the background code works fine which it does.
What am I doing wrong when it comes to constructing the XML for the request? I've read that I need to include xmlns and xmlns:i but I'm not sure what these are for or what to set them to. I've tried various options with no success.