title: WCF restful service: Error the server responded with a status of 405 (Method Not Allowed)
body: <p>i know it's looks like duplicate question.</p>
  
  <p>Here i want to call my wcf rest service using jquery ajax and want to pass country object which have countryname as parameter in rest service. but whenever I am calling my rest service using jquery ajax from html page.but it is giving me error <code>405 method not allowed</code>.I tried lots of time to solve it.but i am enable to solve this error.And i am trying to pass data in json object.</p>
  
  <p><strong>Iservice.cs:</strong></p>
  
  <pre><code>[OperationContract]
      [WebInvoke(UriTemplate = "/AddCountry", ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json)]
      String AddCountry(tableCountry Country);
  </code></pre>
  
  <p><strong>Service.cs</strong></p>
  
  <pre><code>public string AddCountry(tableCountry Country)
  {
      //do Code.
  }
  </code></pre>
  
  <p><strong>Web.config</strong></p>
  
  <pre><code>&lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;webHttpBinding&gt;
                  &lt;binding name="webHttpBinding" crossDomainScriptAccessEnabled="true"&gt;
                      &lt;security mode="None"/&gt;
                  &lt;/binding&gt;
              &lt;/webHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name=""&gt;
                      &lt;serviceMetadata httpGetEnabled="true"/&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
              &lt;endpointBehaviors&gt;
                  &lt;behavior name="webbehaviour"&gt;
                      &lt;webHttp/&gt;
                  &lt;/behavior&gt;
              &lt;/endpointBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;services&gt;
              &lt;service name="Service"&gt;
                  &lt;endpoint address="rest" binding="webHttpBinding" contract="IService" bindingConfiguration="webHttpBinding" behaviorConfiguration="webbehaviour"/&gt;
              &lt;/service&gt;
          &lt;/services&gt;
          &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true"/&gt;  
  &lt;/system.serviceModel&gt;
  &lt;system.webServer&gt;
     &lt;httpProtocol&gt;
       &lt;customHeaders&gt;
         &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
       &lt;/customHeaders&gt;
     &lt;/httpProtocol&gt;
     &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
     &lt;directoryBrowse enabled="true"/&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p><strong>Ajax Code</strong></p>
  
  <pre><code>$("document").ready(function(){    
      var country = {"CountryName":"Iran"};
  
      $.ajax({
          type: "POST",                   
          url: "http://localhost:2293/ACFRestAjaxParsing/Service.svc/rest/AddCountry",    
          data: JSON.stringify({ Country: country }),                 
          contentType: "application/json; charset=utf-8",
          dataType: "jsonp",
          success: function(data){alert(data);},
          failure: function(errMsg) {
              alert(errMsg);
          }
      });
  });
  </code></pre>
  
  <p>I refer this link to solve this error <a href="https://stackoverflow.com/a/6323528/3436627">Stackoverflow</a></p>
  
  <p>If anyone have idea about this error in my case then please help me.</p>
  
  <p>Thanks in advance.</p>