服务器端的MEF(WCF) [英] MEF at server side (WCF)

查看:95
本文介绍了服务器端的MEF(WCF)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在寻找有关如何在WCF中使用MEF的一些指导。
我的服务配置如下: InstanceContextMode = InstanceContextMode 。PerCall,ConcurrencyMode = ConcurrencyMode 。多个。
我需要吗? WCF操作行为会在每次操作调用时创建一个新的目录?
我可以只有一个目录由所有操作共享吗?

祝你...帮助。


philippe

Hello,

I'm looking for some guidance on how to use MEF with WCF.
My services are configured as follows : InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple.
Do I need a WCF operation behavior that would create a new catalog on each operation call ?
Can I have only one catalog shared by all operations ?
...

Thanks for your help.


philippe

推荐答案

嗨Philippe,

在WCF中,IInstanceProvider是如果要覆盖对象创建的自定义行为,则覆盖的接口。您的IInstanceProvider实现需要与服务行为或端点行为联系。

使用ServiceBehavior:

public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
                                           System.ServiceModel.ServiceHostBase serviceHostBase)
   &NBSP ;    {
            foreach(serviceHostBase.ChannelDispatchers中的var channelDispatcherBase)
            {
                VAR channelDispatcher = channelDispatcherBase作为ChannelDispatcher;
               
                if(channelDispatcher == null)
                {继续;}               的foreach(在channelDispatcher.Endpoints VAR endpointDispatcher)
                {
&n&n;                  endpointDispatcher.DispatchRuntime.InstanceProvider =
                        新的 MyCustomInstanceProvider();
                }            }        HTH,

- - larsw
Hi Philippe,

 In WCF, IInstanceProvider is the interface to override if you want to override the custom behavior of object creation. You're IInstanceProvider-implementation needs to be wired up with a service behavior or endpoint behavior.

using a ServiceBehavior:

public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
                                          System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            foreach (var channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                var channelDispatcher = channelDispatcherBase as ChannelDispatcher;
               
                if (channelDispatcher == null)
                {continue;}

                foreach (var endpointDispatcher in channelDispatcher.Endpoints)
                {
                    endpointDispatcher.DispatchRuntime.InstanceProvider =
                        new MyCustomInstanceProvider();
                }
            }
        }



HTH,

 --larsw


这篇关于服务器端的MEF(WCF)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆