title: WCF Web API - Model Binding to an object (Ensure that a request HttpOperationHandler has an output parameter with a type assignable to...)
body: <p>On WCF Web API Preview 5, I am dealing with a strange behavior. Here is the scenario:</p>
  
  <p>This is my model:</p>
  
  <pre><code>public class Person
  {
      public int ID { get; set; }
      public string Name { get; set; }
      public string Surname { get; set; }
      public int Age { get; set; }
  }
  </code></pre>
  
  <p>This is the API:</p>
  
  <pre><code>[ServiceContract]
  public class PersonApi {
  
      [WebGet(UriTemplate = "person?id={ID}&amp;name={Name}&amp;surname={Surname}&amp;age={Age}")]
      public Person Get(Person person) {
  
          return person;
      }
  
  }
  </code></pre>
  
  <p>I registered the API with the following code:</p>
  
  <pre><code>RouteTable.Routes.MapServiceRoute&lt;ADummy.PersonApi&gt;("Dummy");
  </code></pre>
  
  <p>When I run try to reach the service with following URL, I get this error:</p>
  
  <blockquote>
    <p>localhost:36973/Dummy/person?id=1&amp;name=Tugberk&amp;surname=Ugurlu&amp;age=24</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>The service operation 'Get' will never receive a value for the input
    parameter 'person' of type 'Person'. Ensure that a request
    HttpOperationHandler has an output parameter with a type assignable to
    'Person'.</p>
  </blockquote>
  
  <p>But when I change my API logic like below it works:</p>
  
  <pre><code>[ServiceContract]
  public class PersonApi {
  
      [WebGet(UriTemplate = "person?id={ID}&amp;name={Name}&amp;surname={Surname}&amp;age={Age}")]
      public Person Get(int ID, string Name, string Surname, int Age) {
  
          var p = new Person { 
              ID = ID,
              Name = Name,
              Surname = Surname,
              Age = Age
          };
  
          return p;
      }
  
  }
  </code></pre>
  
  <p>In WCF Web API, I suppose things are not working like they work in ASP.NET MVC.</p>
  
  <p>What is way of model binding to an object in WCF Web API?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have added another method:</p>
  
  <pre><code>[WebInvoke(UriTemplate= "put", Method="POST")]
  public Person Put(Person person) {
  
      return person;
  }
  </code></pre>
  
  <p>When I call this method with the following details:</p>
  
  <blockquote>
    <p>Method: POST </p>
    
    <p>URL: <a href="http://localhost:36973/Dummy/put" rel="nofollow">http://localhost:36973/Dummy/put</a></p>
    
    <p>Accept:<em>/</em> Content-Type:text/xml </p>
    
    <p>Content-Length:189</p>
    
    <p>BODY:</p>
  
  <pre><code>&lt;Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;ID&gt;1&lt;/ID&gt;
  &lt;Name&gt;Tugberk&lt;/Name&gt;
  &lt;Surname&gt;Ugurlu&lt;/Surname&gt;
  &lt;Age&gt;25&lt;/Age&gt;
  &lt;/Person&gt;
  </code></pre>
  </blockquote>
  
  <p>I get what I needed. So, query string binding to custom objects is not allowed?</p>