405 WCF Web服务Post方法中不允许出现错误的方法

时间:2016-11-11 07:45:54

标签: jquery asp.net web-services wcf

我正在使用WCF网络服务并收到错误" 405方法不允许"从浏览器调用POST方法但它从PostMan工作正常。 这是我的WCF POST方法代码

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

这是我的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>

这是我的Javascript代码

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);
});

浏览器响应 enter image description here

邮递员回应 enter image description here

1 个答案:

答案 0 :(得分:0)

尝试以下链接,您将获得解决问题的方法

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

相关问题