简体   繁体   English

IIS可以通过assemby解决方案托管Wcf服务吗?

[英]IIS hosted Wcf service with assemby resolution is possible?

Is it possible to load assemblies via assembly resolve event in iis hosted wcf service. 是否可以通过iis托管的wcf服务中的程序集解析事件来加载程序集。 I don't want load assemblies via GAC or bin folder. 我不希望通过GAC或bin文件夹加载程序集。 Is it possible? 可能吗? thanks. 谢谢。

I don't think you can use the AppDomain.AssemblyResolve event, but what you might try is using MEF to resolve actual implementation using a DirectoryCatalog . 我认为您不能使用AppDomain.AssemblyResolve事件,但是您可以尝试使用MEF使用DirectoryCatalog解析实际实现。

So your SVC code behind (or you can remove the code behind and point your SVC to a class in a separate assembly) would look something like this (untested). 因此,您后面的SVC代码(或您可以删除后面的代码,并将SVC指向单独程序集中的类)将看起来像这样(未经测试)。 I've not tried this specific method, but I don't see any reason it wouldn't work. 我没有尝试过这种特定方法,但是我看不出任何不起作用的原因。

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();
    }
}

You could also move the MEF code to a base class if that makes sense. 如果可以的话,您也可以将MEF代码移至基类。 If you're new to MEF, here's a tutorial using MEF with a DirectoryCatalog . 如果您不熟悉 MEF,这是将MEF与DirectoryCatalog结合使用的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM