使用IIS时出现“方法不允许405”错误

6

我有以下的WCF:

    [OperationContract]
    IList<OperationRoomDto> GetOperationRooms();

我有一个使用WCF的网站,当我在Visual Studio中使用(Asp.Net开发服务器)时,一切正常,但当我将WCF部署到IIS时,出现以下异常:

The remote server returned an error: (405) Method Not Allowed.

我创建了一个简单的网站来测试这个WCF(在IIS上),它能够工作。

以下是网站web.config文件的一部分:

  <endpoint address="http://server/WcfService"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMessageService"
            contract="MyProject.Web.Wcf.IMessageService" name="BasicHttpBinding_IMessageService">
  </endpoint>

还有web服务配置文件的这一部分:

  <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

我试图调试w3wp.exe服务,以获取任何隐藏的异常信息,我在web服务方法上设置了断点,但调试器甚至没有到达那里,异常发生在到达web服务类之前。

我曾经遇到过类似的问题,解决方法是从Windows功能中启用HTTP激活 - Nir
当我遇到这个问题时,解决方案是启用HTTP激活 - Nir
1个回答

12

我找到问题所在了,原因是WCF的URL不正确,缺少服务文件名。

<endpoint address="http://server/WcfService"

它应该变成:

<endpoint address="http://server/WcfService/Service.svc"

1
不要啊啊啊啊啊啊啊啊!我已经花了几个小时来解决这个问题,结果发现这就是问题所在。谢谢 :) - Steve Wilkes
1
我很高兴你的问题已经解决了,我也花了很多时间才解决它。 - Nour

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接