Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't deserialize XML in WCF REST service
    text
    copied!<p>I've just started playing with the REST starter kit, and I've hit a road block trying to build my own service. I'm trying to create a service for account management, and I can't get the service to serialize my objects, throwing the following error:</p> <blockquote> <p>Unable to deserialize XML body with root name 'CreateAccount' and root namespace '' (for operation 'CreateAccount' and contract ('Service', '<a href="http://tempuri.org/" rel="nofollow noreferrer">http://tempuri.org/</a>')) using DataContractSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.</p> </blockquote> <p>Here's the actual code for the service (based off of the 'DoWork' method that came with the project):</p> <pre><code>[WebHelp(Comment = "Creates a Membership account")] [WebInvoke(UriTemplate = "CreateAccount", RequestFormat = WebMessageFormat.Xml)] [OperationContract] public ServiceResponse CreateAccount(CreateAccount request) { try { // do stuff return new ServiceResponse() { Status = "SUCCESS", ErrorMessage = "" }; } catch (Exception ex) { return new ServiceResponse() { Status = "ERROR", ErrorMessage = ex.Message + "\n\n" + ex.StackTrace }; } } </code></pre> <p>And last, but not least, here's the object that's causing all the trouble:</p> <pre><code>public class CreateAccount { public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public bool SignUpForNewsletter { get; set; } public string Password { get; set; } } </code></pre> <p>Am I missing anything stupid?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload