title: Web Api call with a complex object as parameter
body: <p>My webApi Controller</p>
  
  <pre><code>[HttpPost]
  public ISearchProviderCommandResult ExecuteCommand(ISearchProviderCommand command)
  {
    MySearchProvider searchProvider = new MySearchProvider();
    return searchProvider.ExecuteCommand(command);
  }
  </code></pre>
  
  <p>My searchCommand object</p>
  
  <pre><code>[Serializable]
  class SearchProviderCommand : ISearchProviderCommand
  {
    public string OperationContext {get; set;}
    public string OperationId{get; set;}
  }
  </code></pre>
  
  <p>I have a break point in my webapi controller and a breakpoint on the line 
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();</p>
  
  <p>When I try to step into the webapi controller, I get a 500 error and it doesnt even hit the breakpoint inside the webapi controller.  Here are my questions:</p>
  
  <ol>
  <li>What am I doing wrong?</li>
  <li>Can I send complex objects to web api requests?</li>
  </ol>
  
  <p>EDIT:
  Based on the asp.net forums and leons directions I changed my WebApi controller to use an object instead of the interface and it works:</p>
  
  <pre><code>[HttpPost]
  public SearchProviderCommandResult ExecuteCommand(SearchProviderCommand command)
  {
    MySearchProvider searchProvider = new MySearchProvider();
    return searchProvider.ExecuteCommand(command);
  }
  </code></pre>
  
  <p>Can you tell me how I reconstruct my object from the result?</p>
  
  <p>EDIT: Based leon's suggestion - for those who are interested here is my final caller code</p>
  
  <pre><code>public result ExecuteCommand(ISearchProviderCommand searchCommand)
  {
    //serialize the object before sending it in
    JavaScriptSerializer serializer = new JavaScriptSerializer();
    string jsonInput = serializer.Serialize(searchCommand);
  
    HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(ServiceUrl) };
    StringContent content = new StringContent(jsonInput, Encoding.UTF8, "application/json");
    var output = httpClient.PostAsync(ServiceUrl, content).Result;
  
    //deserialize the output of the webapi call
    result c = serializer.Deserialize&lt;result&gt;(output.Content.ReadAsStringAsync().Result);
  
    return c;
   }
  }
  
  public class result : ISearchProviderCommandResult
  {
    public object Result { get; set; }
  }
  </code></pre>