title: How to call ASP .NET MVC WebAPI 2 method properly
body: <p>I have created separated project for <strong>ASP .NET MVC WebAPI 2</strong> and I would like to call <code>Register</code> method. (I use a project is created by VS2013 by default.)</p>
  
  <pre><code>[Authorize]
  [RoutePrefix("api/Account")]
  public class AccountController : ApiController
  {
      .... 
  
      // POST api/Account/Register
      [AllowAnonymous]
      [Route("Register")]
      public async Task&lt;IHttpActionResult&gt; Register(RegisterBindingModel model)
      {
          if (!ModelState.IsValid)
          {
              return BadRequest(ModelState);
          }
  
          IdentityUser user = new IdentityUser
          {
              UserName = model.UserName
          };
  
          IdentityResult result = await UserManager.CreateAsync(user, model.Password);
          IHttpActionResult errorResult = GetErrorResult(result);
  
          if (errorResult != null)
          {
              return errorResult;
          }
  
          return Ok();
      }
  </code></pre>
  
  <p>I use a <strong>simple WPF app</strong> to do this. I am not sure about the syntax to call this method and pass username and password to it due<code>RegisterBindingModel</code>.</p>
  
  <pre><code>  public partial class MainWindow : Window
      {
          HttpClient client;
  
          public MainWindow()
          {
              InitializeComponent();        
          }
  
          private  void Button_Click(object sender, RoutedEventArgs e)
          {
              Test();
          }
  
          private async void Test()
          {
              try
              {
                  var handler = new HttpClientHandler();
                  handler.UseDefaultCredentials = true;
                  handler.PreAuthenticate = true;
                  handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
  
                  handler.Credentials = new NetworkCredential("test01","test01"); 
  
                  client = new HttpClient(handler);
                  client.BaseAddress = new Uri("http://localhost:22678/");
                  client.DefaultRequestHeaders.Accept.Add(
                      new MediaTypeWithQualityHeaderValue("application/json")); // It  tells the server to send data in JSON format.
  
                  var response = await client.GetAsync("api/Register");
                  response.EnsureSuccessStatusCode(); // Throw on error code.
  
                  // How to pass RegisterBindingModel ???     
                  var data = await response.Content.ReadAsAsync&lt;?????&gt;();
  
              }
              catch (Newtonsoft.Json.JsonException jEx)
              {
                  MessageBox.Show(jEx.Message);
              }
              catch (HttpRequestException ex)
              {
                  MessageBox.Show(ex.Message);
              }
              finally
              {
              }
          } 
  </code></pre>
  
  <p>Any clue?</p>