I try to submit a request to a REST API using WCF; here's what I've done:
namespace Sample
{
[ServiceContract]
[XmlSerializerFormat]
public interface ISampleApi
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "users.xml", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml)]
User CreateUser(User user);
}
}
And this is my User
Class:
namespace Sample.Entity
{
[XmlRoot("user")]
public class User
{
[XmlElement("company")]
public string Company { get; set; }
[XmlElement("country-code")]
public string ContryCode { get; set; }
[XmlElement("created-at")]
public DateTime CreatedAt { get; set; }
[XmlElement("email")]
public string Email { get; set; }
[XmlElement("external-identifier")]
public string ExternalIdentifier { get; set; }
[XmlElement("id")]
public int Id { get; set; }
[XmlElement("measurement-system")]
public string MeasurmentSystem { get; set; }
[XmlElement("profile")]
public string Profile { get; set; }
[XmlElement("url")]
public string Url { get; set; }
[XmlElement("username")]
public string Username { get; set; }
[XmlElement("account-type")]
public string AccountType { get; set; }
}
}
But when I call CreateUser method and pass a User object to it I receive this error message:
The remote server returned an error: (422) Unprocessable Entity.
Any idea what causes this?