title: Why ASP.NET webmethod returns 500 when query string parameters are passed
body: <p>I have the following webmethod:</p>
  
  <pre><code>[WebMethod(true)]
  [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
  public static String requestLocalCrime(string lat, string lng)
  {
      try
      {
          // Initialize the WebRequest.
  
          String LocalCrime = "http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=" + lat + "&amp;lng=" + lng + "";
  
          WebRequest webRequest;
          WebResponse webResponse;
  
          webRequest = HttpWebRequest.Create(LocalCrime) as HttpWebRequest;
          webRequest.Method = WebRequestMethods.Http.Get;
          webRequest.ContentType = "application/json; charset=utf-8";
          Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
  
          webRequest.Credentials = new NetworkCredential(
                  ConfigurationManager.AppSettings["PoliceAPIUsername"].ToString(),
                  ConfigurationManager.AppSettings["PoliceAPIPassword"].ToString());
  
          // Return the response. 
          webResponse = webRequest.GetResponse();
  
          using (StreamReader reader = new StreamReader(webResponse.GetResponseStream(), encode))
  
          {
              string results = reader.ReadToEnd();
              reader.Close();
              webResponse.Close();
              return results;
          }
  
  
      }
      catch(Exception e) {
          return e.Message;
      }
  }
  </code></pre>
  
  <p>which I am calling via jQuery:</p>
  
  <pre><code> var params = {
              "lat": 50.819522,
              "lng": -0.13642
          }
  
  
  $.ajax({
              type: "GET",
              contentType: "application/json; charset=utf-8",
              data: JSON.stringify({ "lat": params.lat, "lng": params.lng }),
              url: "crimerequest.aspx/requestLocalCrime",
              dataType: "json",
              // success: insertCallback 
              success: function (data) {
                  var result = $.parseJSON(data.d);
              },
              error: function (xhr, ajaxOptions, thrownError) {
                  alert(xhr.status);  // Returns 500
                  alert(thrownError); // Internal Server Error
                  return false;
              }
          });
  </code></pre>
  
  <p>the problem is the current LocalCrime string breaks with a 500 but if I replace it with:</p>
  
  <p><code>String LocalCrime = "http://policeapi2.rkh.co.uk/api/leicestershire/C01/crime"</code></p>
  
  <p>Then suddenly without the query string values it works.</p>
  
  <p>Any help is much appreciated.</p>
  
  <p>Okay I wrote a proxy class so I can debug now. <code>return results;</code> does bring back what I want but it is inside an array, maybe that has to do with it. my data looks like this (probably something in the client side is getting this data wrong):</p>
  
  <pre><code>[
  {
      "category": "other-crime", 
      "id": 378815, 
      "location": {
          "latitude": "50.8188090", 
          "street": {
              "id": 379, 
              "name": "On or near Abbey Road"
          }, 
          "longitude": "-0.1196796"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "anti-social-behaviour", 
      "id": 377906, 
      "location": {
          "latitude": "50.8279907", 
          "street": {
              "id": 4721, 
              "name": "On or near Albion Street"
          }, 
          "longitude": "-0.1336384"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "anti-social-behaviour", 
      "id": 377849, 
      "location": {
          "latitude": "50.8279907", 
          "street": {
              "id": 4721, 
              "name": "On or near Albion Street"
          }, 
          "longitude": "-0.1336384"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "other-crime", 
      "id": 377801, 
      "location": {
          "latitude": "50.8279907", 
          "street": {
              "id": 4721, 
              "name": "On or near Albion Street"
          }, 
          "longitude": "-0.1336384"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "burglary", 
      "id": 377781, 
      "location": {
          "latitude": "50.8279907", 
          "street": {
              "id": 4721, 
              "name": "On or near Albion Street"
          }, 
          "longitude": "-0.1336384"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "vehicle-crime", 
      "id": 376569, 
      "location": {
          "latitude": "50.8279446", 
          "street": {
              "id": 6312, 
              "name": "On or near Alexandra Villas"
          }, 
          "longitude": "-0.1454119"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "anti-social-behaviour", 
      "id": 376525, 
      "location": {
          "latitude": "50.8279446", 
          "street": {
              "id": 6312, 
              "name": "On or near Alexandra Villas"
          }, 
          "longitude": "-0.1454119"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "anti-social-behaviour", 
      "id": 376519, 
      "location": {
          "latitude": "50.8279446", 
          "street": {
              "id": 6312, 
              "name": "On or near Alexandra Villas"
          }, 
          "longitude": "-0.1454119"
      }, 
      "context": "", 
      "month": "2011-04"
  }, 
  {
      "category": "anti-social-behaviour", 
      "id": 376518, 
      "location": {
          "latitude": "50.8279446", 
          "street": {
              "id": 6312, 
              "name": "On or near Alexandra Villas"
          }, 
          "longitude": "-0.1454119"
      }, 
      "context": "", 
      "month": "2011-04"
  }
  ]
  </code></pre>