title: Send JSON to WCF 3.5 using Ajax
body: <p>I'm having issues passing JSON to the Weight method. I keep getting <code>HTTP/1.1 415 Cannot process the message because the content type 'application/x-www-form-urlencoded; charset=UTF-8' was not the expected type 'text/xml; charset=utf-8'.</code></p>
  
  <p>I think I have a problem with either my contract or web.config. All my research turns up empty. I'll be calling this service from a Web Part using jQuery's $.ajax.</p>
  
  <p>Interface:</p>
  
  <pre><code>namespace XXX.SharePoint.WebServices
  {
      [ServiceContract]
      public interface ICalculators
      {
  
          [OperationContract]
          [WebInvoke(Method = "POST",
                     BodyStyle = WebMessageBodyStyle.WrappedRequest,
                     RequestFormat = WebMessageFormat.Json,
                     ResponseFormat = WebMessageFormat.Json
          )]
          Single Weight(Single Width, Single Diameter, Single Size, Single Factor);
      }
  }
  </code></pre>
  
  <p>web.config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="XXX.SharePoint.WebServices.CustomServiceBehaviour"
          name="XXX.SharePoint.WebServices.Calculators"&gt;
          &lt;endpoint address=""
                    binding="basicHttpBinding"
                    contract="XXX.SharePoint.WebServices.ICalculators" &gt;
            &lt;identity&gt;
              &lt;dns value="localhost" /&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://moss2010/"&gt;&lt;/add&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="XXX.SharePoint.WebServices.CustomServiceBehaviour"&gt;
            &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid
  disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>As always, thanks in advance!</p>