title: asmx webservice doesn't read postdata
body: <p>I have an .asmx webservice that works fine except it doesn't read prostdata. It looks like this:</p>
  
  <pre><code>namespace mynamespace.liby
  {
  
      [ScriptService]
      [WebService(Namespace = "http://tempuri.org/")]
      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
      [System.ComponentModel.ToolboxItem(false)]
  
      public class json : System.Web.Services.WebService
      {
  
          [WebMethod]
          [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
          public List&lt;sp_tech_keywordSearch_Result&gt; search()
          {
  
              const string KEY = "key";
              var key = string.Empty;
  
              // convert postdata to dictionary
              // this piece of code works fine in my asp.net MVC controller but not here :-(
              string data = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd();
              Dictionary&lt;string, string&gt; postData = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, string&gt;&gt;(data);
  
              if (postData.ContainsKey(KEY)) { key = postData[KEY]; }
  
              var db = new my_Entities();
              var result = db.sp_myStoredProcedure(key);
  
              return result.ToList();
  
          }
      }
  }
  </code></pre>
  
  <p>If I comment out the line </p>
  
  <pre><code>// if (postData.ContainsKey(KEY)) { key = postData[KEY]; }
  </code></pre>
  
  <p>the procedure is called without parameter and returns a list of values.
  But when I keep this line it throws an error saying <code>postData</code> is null.
  When i check it in debug mode I see that <code>data</code> is an empty string.</p>
  
  <p>I call this service with angular like this:</p>
  
  <pre><code>callService: function () {
      var postData = new Object();
      postData.key =4;
  
      return $http({ method: 'POST', url: MY_SERVICE, data: postData })
          .then(function (obj) {
              _Result = obj.data.d;
              return true;
          }, function (err) {
              _Result = [];
              console.log('serviceError');
              return false;
          });
  },
  </code></pre>
  
  <p>My guess is that my code for reading postdata is wrong somehow. I have the same code running in an ASP.NET MVC controller and it works fine there. Does anyone have an idea on how to fix this?</p>