1

I have an Web-Api project with controllers and all the necessary stuff, which I want to host as Windows Service. I've created new project, and added there a WindowsService and ServiceInstaller items, so my solution looks like this:

Solution structure

My configuration is:

private HttpSelfHostServer _server;
    private readonly HttpSelfHostConfiguration _config;
    public const string ServiceAddress = "http://localhost:333";

    public WebApiService()
    {
        InitializeComponent();

        _config = new HttpSelfHostConfiguration(ServiceAddress);

        // Set our own assembly resolver where we add the assemblies we need
        CustomAssembliesResolver assemblyResolver = new CustomAssembliesResolver();
        _config.Services.Replace(typeof(IAssembliesResolver), assemblyResolver);

        _config.Routes.MapHttpRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = RouteParameter.Optional });
    }

public class CustomAssembliesResolver : DefaultAssembliesResolver
    {
        public override ICollection<Assembly> GetAssemblies()
        {
            ICollection<Assembly> baseAssemblies = base.GetAssemblies();

            List<Assembly> assemblies = new List<Assembly>(baseAssemblies);

            var controllersAssembly = Assembly.LoadFrom(@"D:\Regula\WebApiService\WebApiService\bin\WebApiService.dll");

            baseAssemblies.Add(controllersAssembly);

            return assemblies;
        }
    }

I've tried to follow this thread suggestions, but it did not help me - I'm still getting:

No type was found that matches the controller named 'Home'.

Basically, I' trying to call HomeController located in WebApiService project from WebApiHost project.

Thanks in advance!

2
  • The code for CustomAssembliesResolver seems relevant.
    – Jodrell
    Aug 19, 2013 at 8:17
  • It's copy/pasted from the thread I've specified in my post, just with target assembly path changed.
    – insomnium_
    Aug 19, 2013 at 8:18

1 Answer 1

0

MapHttpRoute is for controllers, derived from ApiController only. HomeController is derived from Controller, so it can't be mapped in this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.