2016-11-11 204 views
1

我正在使用WCF Web服務並從瀏覽器調用POST方法時收到錯誤「405方法不允許」,但它在PostMan中正常工作。 這裏是我的WCF POST方法405 WCF Web服務中的方法不允許錯誤發佈方法

[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

回答

相關問題