1

I have a simple WCF service:

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

        [OperationContract]
        bool NotAttending();
    }

    public class RSVPService : IRSVP
    {
        public RSVPService()
        {
        }

        public bool Attending()
        {
            return true;
        }

        public bool NotAttending()
        {
            return true;
        }
    }
}

I'd like to self-host in a console application like so:

class Program
{
    public static void Main()
    {
        // Create a ServiceHost
        using (ServiceHost serviceHost = new ServiceHost(typeof(RSVPService)))
        {
            // Open the ServiceHost to create listeners 
            // and start listening for messages.
            serviceHost.Open();

            // The service can now be accessed.
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}

So I'm using this app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
  <system.serviceModel>      
    <services>
      <service name="Vert.Host.VertService.RSVPService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Vert" />
          </baseAddresses>
        </host>
        <endpoint
          address="/RSVP"
          binding="basicHttpBinding"
          contract="Vert.Host.VertService.IRSVP" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

As I understand it, this setup would leave me with http://localhost:8080/Vert/RSVP/Attending as a valid REST URI to call from an arbitrary HTTPClient, but the call is hanging indefinitely or coming back with a 0 No Response (I'm using Advanced REST client)

What am I missing?

Matt
  • 1,674
  • 2
  • 16
  • 34
  • 1
    Your current WCF config is for a `basicHttpBinding` - a **SOAP** endpoint..... there's no config for a REST endpoint (that would use a `webHttpBinding`) – marc_s Jan 07 '16 at 05:54
  • Do you have any good resources delineating the two? Beyond MSDN? – Matt Jan 07 '16 at 14:55
  • 1
    Go search ! Tons of good stuff out there, e.g. http://dotnetspeak.com/2012/01/creating-wcf-service-with-soaprest-endpoints or http://www.dotnetcurry.com/wcf/728/expose-wcf-service-soap-rest or answers to [this other SO question here](http://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf-service) – marc_s Jan 07 '16 at 15:01

1 Answers1

2

You are RIGHT in all of your setup...right up to the point where you stopped typing code and started telling me what you have. :)

What you've created is a std WCF service and you can get to it using a Service proxy or a ChannelFactory, but it will communicate with you as-is using SOAP.

You need this tutorial to turn this webservice into a RESTFUL service giving back Json/pox.

Bubba
  • 275
  • 1
  • 10