1

I am using WCF web service and getting the error "405 Method not allowed" while calling POST method from browser but it is working fine from PostMan. Here is my code for WCF POST method

    [OperationContract]
    [WebInvoke(UriTemplate = "pushData", 
               Method = "POST", 
               ResponseFormat = WebMessageFormat.Json,
               RequestFormat = WebMessageFormat.Json, 
               BodyStyle = WebMessageBodyStyle.Bare)]
    bool pushDataForReporting(PushDataWrapUp data);

This this is my web.config

   <system.web>
      <webServices>
         <protocols>
            <add name="HttpSoap" />
            <add name="HttpPost" />
            <add name="HttpGet" />
            <add name="Documentation" />
            <add name="HttpPostLocalhost" />
         </protocols>
      </webServices>
      <compilation targetFramework="4.5" debug="true" />
      <httpRuntime targetFramework="4.5" />
   </system.web>
   <system.serviceModel>
      <standardEndpoints>
         <webScriptEndpoint>
            <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
         </webScriptEndpoint>
      </standardEndpoints>
      <services>
         <service name="WrapUpWebService.WrapUp" behaviorConfiguration="ServiceBehaviour">
            <endpoint address="" binding="webHttpBinding" contract="WrapUpWebService.IWrapUp" behaviorConfiguration="web" />
         </service>
      </services>
      <behaviors>
         <serviceBehaviors>
            <behavior name="ServiceBehaviour">
               <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
               <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
               <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
         </serviceBehaviors>
         <endpointBehaviors>
            <behavior name="web">
               <webHttp />
            </behavior>
         </endpointBehaviors>
      </behaviors>
      <!--<protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>-->
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      <bindings>
         <webHttpBinding>
            <binding name="jsonpWebHttpBinding" crossDomainScriptAccessEnabled="true" />
         </webHttpBinding>
      </bindings>
   </system.serviceModel>
   <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
      <httpProtocol>
         <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS" />
            <add name="Access-Control-Max-Age" value="1728000" />
         </customHeaders>
      </httpProtocol>
      <directoryBrowse enabled="true" />
   </system.webServer>

This my Javascript code

var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/WrapUpWebService/WrapUp.svc/pushData",
"method": "POST",
"headers": {
"content-type": "application/json;charset=utf-8",
"cache-control": "no-cache",
"postman-token": "946a48f2-ae43-4595-62b2-0d9856bd4187"
},
  "processData": false,
  "data": "{\"AgentId\": \"12345\",\"RouterCallKey\":    \"Testing\",\"RouterCallKeyDay\":\"223344\", \"SkillGroupSkillTargetId\":\"12356\",\"SkillGroup\":\"BB\",\"DNIS\" : \"111\",\"ANI\":\"123456\",\"SelectedWrapUpCode\" :\"Testing & testing\"}"
}

 $.ajax(settings).done(function (response) {
 console.log(response);
});

browser response enter image description here

Postman Response enter image description here

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Touqeer
  • 77
  • 9

1 Answers1

0

Try the following link you will get solution for your issue

jQuery .ajax() POST Request throws 405 (Method Not Allowed) on RESTful WCF

Community
  • 1
  • 1
Vinoth
  • 851
  • 7
  • 23
  • Dear Vinoth, Thank you for the answer. I have checked and it is already allowed in IIS and in web.config as well but it is not working for me – Touqeer Nov 11 '16 at 10:36