title: Sending PUT request with object parameter (.NET WCF service)
body: <p>So, there's my question.</p>
  
  <p>I am currently working on a WCF REST Service, and I need now to implement a method that allows me to create an account (user account). Searching on the Web didn't help me this time, that's why I'm asking someone who really know what I mean x).</p>
  
  <p>So, this is my method : </p>
  
  <pre><code>[WebInvoke(Method = "PUT", UriTemplate = "users/{username}", 
      RequestFormat = WebMessageFormat.Xml)]
      [OperationContract]
      void PutUserAccount(string username, User u)
      {
          Debug.WriteLine("Entering method [PutUserAccount]");
          // Check if user exists
          User user = DBManager.FindUser(username);
          if (user == null)
          {
              try
              {
                  //Create or update new user
                  u.Id = GetUserLink(username);
                  u.Notes = GetUserNotesLink(username);
                  u.BlackListed = false;
                  DBManager.AddUser(u);
  
                  // Set status to created and include new URI in Location 
                  //header
                  WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(GetUserProfile(username).Id);
              }
              catch (Exception e)
              {
                  Debug.WriteLine("_PutUserAccount || Exception [" + e.Message + "]");
              }
          }
          else if (!DBManager.IsUserAuthorized(username, WebOperationContext.Current))
          {
              Debug.WriteLine("_PutUserAccount - 1. This user isn't allowed to add users");
              WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Unauthorized;
              return;
          }
      }
  </code></pre>
  
  <p>And this is my "User" class :</p>
  
  <pre><code>[DataContract]
  class _User
  {
      [DataMember]
      public string Id { get; set; }
      [DataMember]
      public string Username { get; set; }
      [DataMember]
      public string Password { get; set; }
      [DataMember]
      public string Name { get; set; }
      [DataMember]
      public string Email { get; set; }
      [DataMember]
      public string Notes { get; set; }
      [DataMember]
      public bool BlackListed { get; set; }
  }
  </code></pre>
  
  <p>And the problem is: I can't do any request to fill "User u" it always returns these exceptions :</p>
  
  <pre><code>Exception thrown: 'System.InvalidOperationException' in 
  System.ServiceModel.Web.dll
  Exception thrown: 'System.InvalidOperationException' in 
  System.ServiceModel.dll
  Exception thrown: 'System.InvalidOperationException' in 
  System.ServiceModel.dll
  Exception thrown: 'System.InvalidOperationException' in 
  System.ServiceModel.dll
  </code></pre>
  
  <p>There is my POSTMAN request: 
  PUT REQUEST: <a href="http://172.20.131.13/TDT/users/" rel="nofollow noreferrer">http://172.20.131.13/TDT/users/</a>{RandomUser}
  And my XML body: </p>
  
  <pre><code>&lt;User&gt;
      &lt;Id&gt;something&lt;/Id&gt;
      &lt;Username&gt;RandomUser&lt;/Username&gt;
      &lt;Password&gt;1234&lt;/Password&gt;
      &lt;Name&gt;Random User&lt;/Name&gt;
      &lt;Email&gt;random.user@randomemail.com&lt;/Email&gt;
      &lt;Notes&gt;http://www.random-link.com&lt;/Notes&gt;
      &lt;BlackListed&gt;false&lt;/BlackListed&gt;
  &lt;/User&gt;
  </code></pre>
  
  <p>My question is, how do I have to build the request to pass a User to my Service ?</p>
  
  <p>P.S. : I am using postman to test my code.</p>