0

Implementing Unity.WCF as seen here: https://unitywcf.codeplex.com/

When I host the service whilst using fileless activation it is still asking me for a default constructor, rather than resolve the Service via unity, I'm unsure what I have missed.

WCFServiceFactory:

public class WcfServiceFactory : UnityServiceHostFactory
{
protected override void ConfigureContainer(IUnityContainer container)
{
        container.RegisterType<IPollerSVC, ProductionHostSVC>()
                 .RegisterType<PeriodicTaskFactory>()
                 .RegisterType<CancellationTokenSource>(new HierarchicalLifetimeManager())
                 .RegisterType<IProcessor, ThirdPartyProcessor>();      
}
}

Web.config:

<?xml version="1.0"?>
<configuration>
  <appSettings/>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- 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 -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment>
      <serviceActivations>
        <add factory="IISHostThirdParty.WcfServiceFactory" relativeAddress="./ProductionHost.svc" service="Service.Common.ProductionHostSVC"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        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.
  -->
    <directoryBrowse enabled="true"/>
  </system.webServer>
</configuration>

Service:

    [ServiceContract(Namespace = "http://Services/IPollerService")]
    public interface IPollerSVC
    {
        Task PollingTask { get; }

    }

[ServiceBehavior(Name = "Services.SL.ThirdParty.ServiceHost", InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = true)]

public class ProductionHostSVC : IPollerSVC
{
    public ProductionHostSVC(IProcessor processor,
                             PeriodicTaskFactory taskFactory,
                             CancellationTokenSource ctks)
    {
        _ctks = ctks;

    }

    public Task PollingTask { get; }
}
2
  • This is a stretch, but you are registering the service with the container before some of its dependencies. Have you tried changing the registration order around so .RegisterType<IPollerSVC, ProductionHostSVC>() is last in ConfigureContainer. Commented Jun 17, 2016 at 17:28
  • I've just had a look and this doesn't work, nice idea though. Commented Jun 20, 2016 at 11:37

1 Answer 1

0

Pretty old but still useful answer is here.

In short: WCF does not call InstanceProvider if InstanceContextMode.Single is used. So Unity.WCF can't be used to instantiate a service.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.