title: jQuery Ajax to asp.net asmx web service throws Request format is invalid: application/json
body: <p>I have jquery call an asp.net webservice with an integer.
  On our legaacy application which was ported to .net 4.0 I cannot get this call to work.
  I can call a method which has no parameters but sending data to the web method returns the following error:</p>
  
  <pre><code>System.InvalidOperationException: Request format is invalid: application/json; charset=UTF-8. 
  at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() 
  at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
  </code></pre>
  
  <p>I created exactly the same code in a blank project and it worked fine. I couldnt see anything in the web.config that the blank project added that would make a difference.</p>
  
  <p>the Jquery Code</p>
  
  <pre><code>$.ajax({
      type: "POST",
      url: "/WebService1.asmx/Test",
      data: JSON.stringify({"code": 1234}),
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function (msg) {
          alert(msg);
      }
  });
  </code></pre>
  
  <p>My Web Service Code</p>
  
  <pre><code>&lt;ScriptService()&gt; _
  &lt;WebService(Namespace:="http://tempuri.org/")&gt; _
  &lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _
  &lt;ToolboxItem(False)&gt; _
  Public Class WebService1
      Inherits WebService
  
      &lt;WebMethod()&gt;
      Public Function Test(ByVal code As Integer) As String
          Return "success"
      End Function
  
      &lt;WebMethod()&gt;
      Public Function Hello() As String
          Return "hello"
      End Function    
  End Class
  </code></pre>
  
  <p>Web Config</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;  
      &lt;appSettings&gt;
      &lt;/appSettings&gt;
      &lt;connectionStrings&gt;
      &lt;/connectionStrings&gt;
      &lt;system.web&gt;
          &lt;httpRuntime enableVersionHeader="false" /&gt;
          &lt;httpCookies httpOnlyCookies="true" requireSSL="false" lockItem="true" /&gt;
          &lt;trace enabled="false" pageOutput="true" requestLimit="40" localOnly="true"/&gt;
  
          &lt;httpModules&gt;
          &lt;/httpModules&gt;
          &lt;compilation debug="true" strict="true" explicit="true" targetFramework="4.0"&gt;
  
          &lt;/compilation&gt;
          &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"&gt;
          &lt;/pages&gt;
  
          &lt;authentication mode="Forms"&gt;
  
          &lt;httpHandlers&gt;     
          &lt;/httpHandlers&gt;
      &lt;/system.web&gt;
  
      &lt;system.webServer&gt;
  
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules&gt;
      &lt;/modules&gt;
      &lt;handlers&gt;
      &lt;/handlers&gt;
      &lt;httpErrors errorMode="Custom" &gt; 
      &lt;/httpErrors&gt;
      &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>