【问题标题】:IIS hosted Wcf service with assemby resolution is possible?IIS 托管具有程序集解析的 Wcf 服务是可能的吗?
【发布时间】:2011-08-03 01:04:21
【问题描述】:

是否可以通过 iis 托管的 wcf 服务中的程序集解析事件加载程序集。我不想通过 GAC 或 bin 文件夹加载程序集。可能吗?谢谢。

【问题讨论】:

  • 所以您希望实现程序集位于“自定义”位置?
  • @brandon 是自定义位置。

标签: c# wcf iis hosting


【解决方案1】:

我认为您不能使用 AppDomain.AssemblyResolve 事件,但您可能会尝试使用 using MEF 来解决使用 DirectoryCatalog 的实际实现。

因此,您的 SVC 代码(或者您可以删除后面的代码并将您的 SVC 指向单独程序集中的类)看起来像这样(未经测试)。我没有尝试过这种特定的方法,但我看不出它有什么不起作用的原因。

public class YourServiceClass : YourServiceContract
{
    [Import]
    private IContract Implementation { get; set; }

    private DirectoryCatalog _directoryCatalog = null;
    private CompositionContainer _container = null;

    public YourServiceClass()
    {
        _directoryCatalog = new DirectoryCatalog(YourDirectoryPathHere);
        _container = new CompositionContainer(_directoryCatalog);
        _container.ComposeParts(this);
    }

    //Operation
    public void DoSomething()
    {
        Implementation.DoSomething();
    }
}

如果有意义的话,您还可以将 MEF 代码移至基类。如果您是 MEF 新手,这里有一个教程 using MEF with a DirectoryCatalog

【讨论】:

    猜你喜欢
    • 2022-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多