Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A registration of REST WCF service is almost similar to registration non-REST WCF service. Only changed a few things: bindings, endpoints and service contract.</p> <h2>Modified example from the autofac wiki with WCF REST service (very simplified).</h2> <p>The interface and implementation for the logger that will be the dependency.</p> <pre><code>public interface ILogger { void Write(string message); } public class Logger : ILogger { public void Write(string message) { Console.WriteLine(message); } } </code></pre> <p>The contract and implementation for the rest wcf service.</p> <pre><code>[ServiceContract] public interface IEchoService { [OperationContract] [WebGet(UriTemplate = "/Echo/{message}")] string RestEcho(string message); } public class EchoService : IEchoService { private readonly ILogger _logger; public EchoService(ILogger logger) { _logger = logger; } public string RestEcho(string message) { _logger.Write(message); return message; } } </code></pre> <p>The Console Application code for building the container and hosting the web service.</p> <pre><code>class Program { static void Main() { ContainerBuilder builder = new ContainerBuilder(); builder.Register(c =&gt; new Logger()).As&lt;ILogger&gt;(); builder.Register(c =&gt; new EchoService(c.Resolve&lt;ILogger&gt;())).As&lt;IEchoService&gt;(); using (IContainer container = builder.Build()) { Uri address = new Uri("http://localhost:8080/EchoService"); ServiceHost host = new ServiceHost(typeof(EchoService), address); var binding = new WebHttpBinding(); var endpointAddress = new EndpointAddress(address); var description = ContractDescription.GetContract(typeof(IEchoService)); var endpoint = new ServiceEndpoint(description, binding, endpointAddress); endpoint.Behaviors.Add(new WebHttpBehavior { HelpEnabled = true }); host.AddServiceEndpoint(endpoint); host.AddDependencyInjectionBehavior&lt;IEchoService&gt;(container); host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true, HttpGetUrl = address }); host.Open(); Console.WriteLine("The host has been opened."); Console.ReadLine(); host.Close(); Environment.Exit(0); } } } </code></pre> <p>For testing, run any browser and open a url <code>http://localhost:8080/EchoService/Echo/test_test</code> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload