WCF error : 405 Method Not Allowed

前端 未结 4 1219
臣服心动
臣服心动 2020-12-01 14:19

Going nuts with this issue. I have a solution with 2 projects, one of them is a plain old html with jquery ajax call while the other is a WCF service. The html page will iss

4条回答
  •  無奈伤痛
    2020-12-01 14:51

    You need to use JSONP for a cross-domain call to get round the browser restrictions, and to update your web.config with crossDomainScriptAccessEnabled set to true to get round server ones. There's a good example in the answer here: how to avoid cross domain policy in jquery ajax for consuming wcf service?

    You may also have a problem with GET requests. Try the fixes outlined here: Making a WCF Web Service work with GET requests

    Altogether, you want a web.config that looks something like this:

    
      
        
      
    
    
      
        
          
        
      
               
         
            
            
         
      
    
    
      
         
      
    
    

    (Note that both the service and the endpoint have behaviours attached, allowing webHttp calls and httpGet calls respectively, and that the binding has crossDomain access explicitly enabled).

    ... a service method decorated like this:

    [ServiceContract]
    public interface IMyService
    {
        [WebGet] // Required Attribute to allow GET
        [OperationContract]
        string MyMethod(string MyParam);
    }
    

    ... and a client call using JSONP:

    
    

提交回复
热议问题