Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不允许死简单的WCF-405方法_C#_Wcf_App Config - Fatal编程技术网

C# 不允许死简单的WCF-405方法

C# 不允许死简单的WCF-405方法,c#,wcf,app-config,C#,Wcf,App Config,据我所知,我模仿了和的公认解决方案。除非我是瞎子(我希望我现在是瞎子),否则我的非常简单的WCF服务有一个一尘不染的app.config: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />

据我所知,我模仿了和的公认解决方案。除非我是瞎子(我希望我现在是瞎子),否则我的非常简单的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>
我通过控制台应用程序托管所有内容:

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方法作为响应。我正在使用Visual Studio Community 2015,IIS10,目标是.NET 4.6

我从建议中尝试过的东西:

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

我遗漏了什么?

老实说,我不确定这是否会产生影响,但我的遗漏与服务行为有关。为您的服务行为命名:

<serviceBehaviors>
    <behavior name="ServiceBehavior">

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


确保使用
[WebGet]
属性装饰服务方法(参考
System.ServiceModel.Web.dll

即,将服务从

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

    public bool NotAttending()
        return true;
}


解决了这个问题。

我尝试发布此帖子的第一件事。不走运:(当时不知道。我的工作很大程度上是靠运气。我只能建议打开日志,看。
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;
}