【问题标题】:Dead simple WCF - 405 Method not allowedDead simple WCF - 405 Method not allowed
【发布时间】:2016-04-12 15:01:49
【问题描述】:

据我所知我已经模仿了this postthis post已接受 解决方案。除非我是盲人(我希望我现在是盲人),否则我非常简单的 WCF 服务有一个一尘不染的app.config

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="RESTBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service name="Vert.Host.VertService.RSVPService">
    <endpoint
      address="/RSVP"
      binding="webHttpBinding"
      contract="Vert.Host.VertService.IRSVP"
      behaviorConfiguration="RESTBehavior" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/Vert" />
      </baseAddresses>
    </host>
  </service>
</services>
</system.serviceModel>

这是相应的服务合同和实施:

namespace Vert.Host.VertService
{
    [ServiceContract]
    public interface IRSVP
    {
        [OperationContract]
        bool Attending();

        [OperationContract]
        bool NotAttending();
    }

    public class RSVPService : IRSVP
    {
        public bool Attending()
            return true;

        public bool NotAttending()
            return true;
    }
}

我通过控制台应用托管所有内容:

class Program
{
    public static void Main()
    {
        // Create a ServiceHost
        using (ServiceHost serviceHost = new ServiceHost(typeof(RSVPService)))
        {
            serviceHost.Open();
            // The service can now be accessed.
            Console.ReadLine();
        }
    }
}

我想要做的就是让这个小服务站起来,但我不能用http://localhost:8080/Vert/RSVP/Attending 到达这个端点。我仍然收到405 Method not allowed 作为响应。我正在使用 Visual Studio Community 2015,IIS10,目标是 .NET 4.6

我从建议中尝试过的事情:

  • 我为我的服务提供了一个明确命名的行为。不走运。

我错过了什么?

【问题讨论】:

    标签: c# wcf app-config


    【解决方案1】:

    老实说,我不确定这是否会有所作为,但我的有一个指向服务行为的链接。为您的服务行为命名:

    <serviceBehaviors>
        <behavior name="ServiceBehavior">
    

    然后将其链接到您的服务:

    &lt;service name="Vert.Host.VertService.RSVPService" behaviorConfiguration="ServiceBehavior"&gt;

    【讨论】:

    • 我在发布此帖子后尝试的第一件事。没有运气:(
    • 那时不知道。我在很大程度上是靠运气来工作的。我只能建议打开日志记录,请参阅this post
    【解决方案2】:

    一定要用[WebGet]属性装饰服务方法(参考System.ServiceModel.Web.dll

    即将服务从

    public class RSVPService : IRSVP
    {
        public bool Attending()
            return true;
    
        public bool NotAttending()
            return true;
    }
    

    public class RSVPService : IRSVP
    {
        [WebGet]
        public bool Attending()
            return true;
    
        [WebGet]
        public bool NotAttending()
            return true;
    }
    

    解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 2019-08-10
      • 1970-01-01
      • 2014-08-31
      • 2011-09-25
      • 2015-07-29
      • 2018-07-15
      相关资源
      最近更新 更多