简体   繁体   English

在WCF服务库项目中使用自定义ServiceHostFactory

[英]Using a custom ServiceHostFactory in a WCF Service Library project

I'm programming a WCF service that internally relies heavily on Inversion of Control. 我正在编写一个内部严重依赖于控制反转的WCF服务。 I would like to bootstrap / initialize my IoC container inside a custom ServiceHostFactory. 我想在自定义ServiceHostFactory中引导/初始化我的IoC容器。 I've read some examples of different hooks that are available, but none of them seem to work for me. 我已经阅读了一些可用的不同钩子的例子,但它们似乎都不适用于我。

This approach is the one I'd prefer to use (custom IServiceBehavior, IInstanceProvider, ServiceHost and ServiceHostFactory) but the last step is to signal to the service to use my custom ServiceHostFactory inside my serivce's *.svc-file. 这种方法是我更喜欢使用的方法(自定义IServiceBehavior,IInstanceProvider,ServiceHost和ServiceHostFactory),但最后一步是向服务发出信号,要求在我的serivce的* .svc文件中使用我的自定义ServiceHostFactory。 I don't have one of those since the project type is a WCF Service Library - not a WCF Service Application. 我没有其中之一,因为项目类型是WCF服务库 - 而不是WCF服务应用程序。 Is there a way I can tell WCF to use my ServiceHostFactory in the App.config file? 有没有办法告诉WCF在App.config文件中使用我的ServiceHostFactory?

Ciddan, glad to see you found a resolution (albeit not perfect). Ciddan,很高兴看到你找到了一个解决方案(尽管并不完美)。 I had the same question as you and finally settled with using IIS to host the service and wired up my Ioc custom classes (that reside in my WCF Service Library) using the serviceHostingEnvironment in my web.config. 我和你有同样的问题,最后使用IIS来托管服务,并使用web.config中的serviceHostingEnvironment连接我的Ioc自定义类(驻留在我的WCF服务库中)。 Something along these lines: 这些方面的东西:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    <serviceActivations>
        <add relativeAddress="./Service1.svc" service="WcfServiceLibrary1.Service1"
          factory="WcfServiceLibrary1.IocServiceHostFactory, WcfServiceLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </serviceActivations>
</serviceHostingEnvironment>

"./Service1.svc" is my fileless service location where as WcfServiceLibrary1.Service1 is the concrete imp. “./Service1.svc”是我的无文件服务位置,其中WcfServiceLibrary1.Service1是具体的imp。 I did hit a few stumbling blocks but in the end managed to encapsulate the Ioc from within the WCF Service Library. 我确实遇到了一些绊脚石,但最终设法从WCF服务库中封装了Ioc。

This blog post was very helpful and has a few great tips. 这篇博客文章非常有用,并有一些很棒的提示。

As I don't see an anwer, I'll post what I found, which is not very encouraging. 由于我没有看到anwer,我会发布我发现的内容,这不是很令人鼓舞。

All references to ServiceHostFactory point to the svc file and the Factory attribute, which is not what you are looking for. 对ServiceHostFactory的所有引用都指向svc文件和Factory属性,这不是您要查找的内容。

This thread on MSDN even tells that it is not possible to do what you are trying to achieve. MSDN上的这个线程甚至告诉你不可能做你想要实现的。

Sorry... 抱歉...

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

相关问题 是否可以使用属性更改WCF服务的ServiceHostFactory? - Is it possible to change a WCF service's ServiceHostFactory using attributes? Sharepoint 2010中的WCF服务找不到我的自定义ServiceHostFactory类 - WCF Service in Sharepoint 2010 can't find my Custom ServiceHostFactory class WCF:NetMsmq而不是Http的应用程序池挂起后,自定义ServiceHostFactory错误 - WCF: Custom ServiceHostFactory errors after Application Pool suspension for NetMsmq but not Http 如何为没有SVC文件的自托管WCF服务指定ServiceHostFactory - How to specify ServiceHostFactory for self-hosted WCF service with no SVC file NServiceBus Transport 在使用自定义 ServiceHostFactory 时为 NULL,WAS - NServiceBus Transport is NULL when using a custom ServiceHostFactory, WAS 在作为Windows服务托管的WCF类库项目中使用SqlDependency - Using SqlDependency in WCF Class Library project hosted as Windows Service WCF服务库项目找不到对其他项目的引用 - WCF service library project can't find reference to other project Windows Service中的Wcf库 - Wcf library in Windows Service 从客户端使用WCF服务,而没有WCF服务库项目/程序集参考 - Consume WCF service from client without WCF Service Library project/assembly reference WCF项目库 - WCF Project library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM