2

As far as I can tell I have mimicked the accepted solutions of this post and this post. Unless I'm blind (and I hope I am at this point), I have a spotless app.config for my very simple WCF service:

<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>

Here's the corresponding Service Contract and Implementation:

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;
    }
}

I'm hosting everything via a console app:

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();
        }
    }
}

All I want to do is stand this tiny service up, but I can't hit this endpoint with http://localhost:8080/Vert/RSVP/Attending. I still get 405 Method not allowed as a response.I'm using Visual Studio Community 2015, IIS10, targeting .NET 4.6

Things I've tried from suggestions:

  • I've given my service an explicitly-named behavior. No luck.

What am I missing?

Community
  • 1
  • 1
Matt
  • 1,674
  • 2
  • 16
  • 34

2 Answers2

0

Honestly not sure if this will make the difference, but mine has a link to service behaviour. Give your service behaviour a name:

<serviceBehaviors>
    <behavior name="ServiceBehavior">

Then link it to your service:

<service name="Vert.Host.VertService.RSVPService" behaviorConfiguration="ServiceBehavior">

Ian
  • 1,475
  • 2
  • 15
  • 31
  • First thing I tried post-posting this post. No luck :( – Matt Jan 08 '16 at 02:23
  • 1
    Don't know then. I largely got mine working through blind luck. I can only recommend turning on logging, see [this post](http://stackoverflow.com/a/10905836). – Ian Jan 08 '16 at 02:31
0

Be sure to decorate the service methods with the [WebGet] attribute (reference System.ServiceModel.Web.dll)

I.e. changing the service from

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

    public bool NotAttending()
        return true;
}

to

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

    [WebGet]
    public bool NotAttending()
        return true;
}

Solves the issue.

Matt
  • 1,674
  • 2
  • 16
  • 34