簡體   English   中英

Unity.WCF要求默認構造函數

[英]Unity.WCF Asking for default constructor

如此處所示,實現Unity.WCF: https ://unitywcf.codeplex.com/

當我在使用無文件激活的同時托管服務時,它仍在詢問我默認的構造函數,而不是通過統一方式解決服務,我不確定我錯過了什么。

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>

服務:

    [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; }
}

相當老但仍然有用的答案在這里。

簡而言之:WCF不調用InstanceProvider如果InstanceContextMode.Single使用。 因此,Unity.WCF不能用於實例化服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM