阻止 DiscoveryEndpoint 创建服务实例

发布于 2024-10-07 03:15:05 字数 265 浏览 0 评论 0原文

我在 WCF 中使用 DiscoveryEndpoints,但我注意到,当发现服务并联系 DiscoveryEndpoint 时,它实际上会导致创建该服务的实例。我不想要这个。

这几乎肯定与我使用自定义实例提供程序(以支持 StructureMap)有关 - 它将自定义 InstanceProvider 应用于每个 EndpointDispatcher。

看来我只想将自定义 InstanceProvider 应用于其合同实际上与服务实现匹配的端点。

有什么想法吗?

I am using DiscoveryEndpoints in WCF but I have noticed that when a service is being discovered and the DiscoveryEndpoint is contacted it will actually cause an instance of the service to be created. I do not want this.

This is almost certainly related to the fact I am using a custom instance provider (to support StructureMap) - which applies custom InstanceProvider to each EndpointDispatcher.

It seems I only want to apply the custom InstanceProvider for the endpoints whose contract actually match the service implementation.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-10-14 03:15:05

我想我已经解决了......我只是忽略任何设置了 IsSystemEndpoint 的内容:

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
        {
            ChannelDispatcher cd = cdb as ChannelDispatcher;
            if (cd != null)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {
                    if (!ed.IsSystemEndpoint) // Ignore MEX etc
                        ed.DispatchRuntime.InstanceProvider =
                            new StructureMapInstanceProvider(serviceDescription.ServiceType);
                }
            }
        }
    }

I think I worked it out... I am just ignoring anything that has IsSystemEndpoint set:

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
        {
            ChannelDispatcher cd = cdb as ChannelDispatcher;
            if (cd != null)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {
                    if (!ed.IsSystemEndpoint) // Ignore MEX etc
                        ed.DispatchRuntime.InstanceProvider =
                            new StructureMapInstanceProvider(serviceDescription.ServiceType);
                }
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文