Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I host a rest service with autofac and wcf?
    primarykey
    data
    text
    <p>Following this guide I managed to get a service working over iis with was. <a href="https://code.google.com/p/autofac/wiki/WcfIntegration#Self-Hosted_Services" rel="nofollow">https://code.google.com/p/autofac/wiki/WcfIntegration#Self-Hosted_Services</a></p> <p>However, I also need it host a rest service. I could actually live with only rest. </p> <p>But with the documentation available I have not been successful yet.</p> <p>Does anyone have a good guide for getting it working with rest service with wcf(was)+autofac?</p> <p>I do not seem to get the endpoint right, no endpoint at all actually.</p> <p>My code, where did I miss something? </p> <pre><code>namespace WcfServiceHost.Infrastructure { public class AutofacContainerBuilder { public static IContainer BuildContainer() { var builder = new ContainerBuilder(); builder.RegisterType&lt;LoginFactory&gt;().As&lt;ILoginFactory&gt;(); builder.RegisterType&lt;SupplierHandler&gt;().As&lt;ISupplierHandler&gt;(); builder.RegisterType&lt;UserHandler&gt;().As&lt;IUserHandler&gt;(); builder.RegisterType&lt;SupplierRepository&gt;().As&lt;ISupplierRepository&gt;(); builder.RegisterType&lt;TidsamProductSupplierProxy&gt;().As&lt;ILogin&gt;(); builder.RegisterType&lt;StoreService&gt;().As&lt;IStoreService&gt;(); //builder.RegisterType&lt;StoreService&gt;(); return builder.Build(); } } } &lt;%@ ServiceHost Language="C#" Debug="true" Service="Services.IStoreService, Services" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %&gt; namespace WcfServiceHost.App_Code // ReSharper restore CheckNamespace { public static class AppStart { public static void AppInitialize() { // Put your container initialization here. // build and set container in application start IContainer container = AutofacContainerBuilder.BuildContainer(); AutofacHostFactory.Container = container; // AutofacWebServiceHostFactory AutofacServiceHostFactory RouteTable.Routes.Add(new ServiceRoute("StoreService", new RestServiceHostFactory&lt;IStoreService&gt;(), typeof(StoreService))); } } } public class RestServiceHostFactory&lt;TServiceContract&gt; : AutofacWebServiceHostFactory { protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) { ServiceHost host = base.CreateServiceHost(serviceType, baseAddresses); var webBehavior = new WebHttpBehavior { AutomaticFormatSelectionEnabled = true, HelpEnabled = true, FaultExceptionEnabled = true }; var endpoint = host.AddServiceEndpoint(typeof(TServiceContract), new WebHttpBinding(), "Rest"); endpoint.Behaviors.Add(new WebHttpBehavior { HelpEnabled = true }); endpoint.Name = "rest"; endpoint.Behaviors.Add(webBehavior); return host; } } </code></pre> <p>config: </p> <pre><code>&lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.5" /&gt; &lt;httpRuntime targetFramework="4.5"/&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior&gt; &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt; &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt; &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --&gt; &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"&gt; &lt;serviceActivations&gt; &lt;add factory="Autofac.Integration.Wcf.AutofacServiceHostFactory" relativeAddress="~/StoreService.svc" service="Services.StoreService" /&gt; &lt;/serviceActivations&gt; &lt;/serviceHostingEnvironment&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"&gt; &lt;add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt; &lt;/modules&gt; &lt;handlers&gt; &lt;add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" /&gt; &lt;/handlers&gt; &lt;!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --&gt; &lt;directoryBrowse enabled="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>Then I do get an endpoint. But as soon as I change to AutofacWebServiceHostFactory I get no endpoint and no rest/help. However, I can query the rest services in IStoreService.</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