title: C# Rest Webservice with ASP.NET MVC 4
body: <p>I created a Rest Webservice with ASP.NET MVC 4 Web Application. If I want to consume the service and send a request including a requestbody the input parameter CoreMessage item is always null. I watched some sample tutorials and some sample code but I couldn't fix the bug. </p>
  
  <p>Some code of my Rest Client</p>
  
  <pre><code>        CoreMessage message = new CoreMessage() { Source = "Dummy", Date = DateTime.Now, Data = "abcd" };
          var url = "http://localhost:12294/api/message";
          var method = "POST";
          string reponseAsString = "";
          try
          {
              var request = (HttpWebRequest)WebRequest.Create(url);
              request.Method = method;
  
              using (Stream requestStream = request.GetRequestStream())
              using (StreamWriter writer = new StreamWriter(requestStream))
              {
                  writer.Write(message);  
              }
          }
          catch (Exception ex)
          {
              reponseAsString += "ERROR: " + ex.Message;
          }
  </code></pre>
  
  <p>My Controller with the Post function look like this</p>
  
  <pre><code>public MessageRepository repository = new MessageRepository();
  
          public HttpResponseMessage PostMessage(CoreMessage item)
          {
              bool status = repository.TransmitMessage(item);
              var response = Request.CreateResponse&lt;bool&gt;(HttpStatusCode.Created, status);
  
              return response;
          }
  </code></pre>
  
  <p>My Model</p>
  
  <pre><code>public class CoreMessage
  {
      public string Source { get; set; }
      public DateTime Date { get; set; }
      public string Data { get; set; }
  }
  </code></pre>