REST in WCF is not that difficult once you figure it out.
You must first define your interface.
Here is an example.
[ServiceContract] public interface IRESTExample { [WebGet(UriTemplate = "interaction/queue?s={site}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] [OperationContract] string QueueInteraction(string site); [WebGet(UriTemplate = "interaction/cancel?id={interactionId}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] [OperationContract] string CancelInteraction(string interactionId); [WebGet(UriTemplate = "queue/state?s={site}&q={queue}", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)] [OperationContract] string QueueState(string site, string queue); }
In WebGet, you can define the final URL. So it depends on where you connect it, but say that you are binding the endpoint to www.example.com/rest
QueueInteraciton will be www.example.com/rest/interaction/queue?s=SomeSite
If {stie} or {parameterName} is replaced with the parameter name.
Execution is just a class, I'm going to assume that you know how to implement an interface. If you need help just leave a comment.
Now snap the endpoint. In the end, it is not so difficult, you can do it all in the config.
<system.serviceModel> <services> <service name="Stackoverflow.Example.Service.RestExample" behaviorConfiguration="MyServiceTypeBehaviors"> <host> <baseAddresses> <add baseAddress="http://localhost:2136/RestExample"/> </baseAddresses> </host> <endpoint address="rest" binding="webHttpBinding" behaviorConfiguration="xmlBehavior" contract="Stackoverflow.Example.Service.IRESTExample" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MyServiceTypeBehaviors" > <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="jsonBehavior"> <webHttp/> </behavior> <behavior name="xmlBehavior"> <webHttp/> </behavior> </endpointBehaviors> </behaviors> <bindings> <basicHttpBinding> <binding name = "NoSecurity"> <security mode = "None" /> </binding> </basicHttpBinding> </bindings> </system.serviceModel>
Now enter the code to start the service and link it. You can do this in everything, for example, in a console application.
RestExample exampleService = new RestExample(); host = new ServiceHost(exampleService); host.Open();
That should be enough to get started.