WCF 405方法不允许疯狂错误帮助!

问题描述:

我疯了我已经阅读了10多篇文章也关于我在调用webservice以平静的方式,并应该启用此服务和webconfig,所以我这样做,但只要我添加[WebGet() ]属性,如果我删除我得到这个疯狂的错误,那么该服务获得无缝称为WCF 405方法不允许疯狂错误帮助!

我使用

  • VS 2010 RC 1
  • IIS 7
  • Windows 7的

这里是我的代码

[ServiceContract(Namespace = "")] 
[AspNetCompatibilityRequirements(RequirementsMode  
=AspNetCompatibilityRequirementsMode.Allowed)] 
public class Service2 
{ 

[OperationContract] 
[WebGet()] 
public List<Table1> GetCustomers(string numberToFetch) 
{ 
    using (DataClassesDataContext context = new DataClassesDataContext()) 
    { 

     return context.Table1s.Take(numberToFetch).ToList(); 
    } 
} 

} 

和我的ASPX页面代码

<body xmlns:sys="javascript:Sys" 
    xmlns:dataview="javascript:Sys.UI.DataView"> 
    <div id="CustomerView" 
     class="sys-template" 
     sys:attach="dataview" 
     dataview:autofetch="true" 
     dataview:dataprovider="Service2.svc" 
     dataview:fetchParameters="{{ {numberToFetch: 2} }}" 
     dataview:fetchoperation="GetCustomers"> 
     <ul> 
      <li>{{name}}</li> 
     </ul> 
    </div> 

和我的web.config代码

<system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior name="Service2AspNetAjaxBehavior"> 
       <enableWebScript /> 
      </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
     multipleSiteBindingsEnabled="true" /> 
    <services> 
     <service name="Service2"> 
      <endpoint address="" behaviorConfiguration="Service2AspNetAjaxBehavior" 
       binding="webHttpBinding" contract="Service2" />    
     </service> 
    </services> 
</system.serviceModel> 

完全欣赏的帮助

尝试添加方法装修:

[WebInvoke(Method = "GET")] 

此外,如果您尝试向不同域或端口上的服务发出请求,您将遇到Firefox中的跨域问题。因此,如果您的Web应用程序运行在localhost:80,并且您的WCF服务设置为localhost:10305,则Firefox将返回一个405.

+0

虽然它是旧的,但投票支持firefox相关解决方案。 – sansknwoledge 2013-03-15 08:06:59