来自同一WCF服务主机中不同服务的多个端点

时间:2022-06-03 09:08:20

I'm trying to write something to help me monitor my WCF services in a custom way. For that, my intention is to write a class implementing a service contract, lets call it IMonitorService, and whenever I want to host any of my normal services, lets say IBusinessService, I'd like to be able to create the normal endpoints for my business service and in addition an endpoint implementing IMonitorService. That way I can call all the monitor endpoints from all my services and read what I need. Is this even possible? I'm not saying it is possible to do this way but something like this would be great:

我正在尝试写一些东西来帮助我以自定义方式监控我的WCF服务。为此,我的目的是编写一个实现服务契约的类,让我们称之为IMonitorService,每当我想托管我的任何正常服务时,让我们说IBusinessService,我希望能够为我创建正常的端点。业务服务以及实现IMonitorService的端点。这样我就可以从我的所有服务中调用所有监控端点,并阅读我需要的内容。这有可能吗?我不是说可以这样做,但是这样的事情会很棒:

var serviceHost = new ServiceHost(typeof(BusinessService), baseAddresses);
var monitorService = new MonitorService(servicehost.Description);
serviceHost.AddServiceEndpoint(typeof(IMonitorService), whatever_binding, monitorService);

I know microsoft already does this for IMetadataExchange and discovery endpoints but I can't seem to understand how to do it myself. How are those implemented?

我知道微软已经为IMetadataExchange和发现端点做了这个,但我似乎无法理解如何自己做。这些是如何实施的?

Currently I'm resorting to open 2 service hosts and chaining their open/close events to that the main one closes the monitoring one and it is less than ideal. Even if it is not as simple as I hope it would be, I'm open to easier alternatives than what I'm doing now.

目前我正在使用开放的2个服务主机并将它们的打开/关闭事件链接到主要的关闭监视器并且它不太理想。即使它不像我希望的那样简单,我也会比我现在所做的更容易。

1 个解决方案

#1


0  

It is possible to do what you want, but it is not easy to do. I did it once, but honestly and took quite a bit of work, but not sure how much any of that stuff has changed (in my case, I wanted a regular HTTP endpoint before WebHttpBinding came around, so it was actually a lot more complex).

可以做你想做的事,但这并不容易。我曾经做过一次,但老实说并且做了很多工作,但不确定这些东西有多少变化(在我的情况下,我想在WebHttpBinding到来之前有一个常规的HTTP端点,所以它实际上要复杂得多)。

It's possible this is a lot easier now, but in case it is useful, here's some articles I wrote about it back then:

现在这可能会变得容易多了,但是如果有用的话,这里有一些关于它的文章:

The resulting code from that investigation can be found here: http://quickcounters.codeplex.com/SourceControl/latest#QuickCounters_net2/WCFSupport/QuickCounters.Wcf/InstrumentedServiceAttribute.cs

调查结果代码可以在这里找到:http://quickcounters.codeplex.com/SourceControl/latest#QuickCounters_net2/WCFSupport/QuickCounters.Wcf/InstrumentedServiceAttribute.cs

In particular, look at the code for the AddHttpGetDispatcher() method.

特别是,请查看AddHttpGetDispatcher()方法的代码。

#1


0  

It is possible to do what you want, but it is not easy to do. I did it once, but honestly and took quite a bit of work, but not sure how much any of that stuff has changed (in my case, I wanted a regular HTTP endpoint before WebHttpBinding came around, so it was actually a lot more complex).

可以做你想做的事,但这并不容易。我曾经做过一次,但老实说并且做了很多工作,但不确定这些东西有多少变化(在我的情况下,我想在WebHttpBinding到来之前有一个常规的HTTP端点,所以它实际上要复杂得多)。

It's possible this is a lot easier now, but in case it is useful, here's some articles I wrote about it back then:

现在这可能会变得容易多了,但是如果有用的话,这里有一些关于它的文章:

The resulting code from that investigation can be found here: http://quickcounters.codeplex.com/SourceControl/latest#QuickCounters_net2/WCFSupport/QuickCounters.Wcf/InstrumentedServiceAttribute.cs

调查结果代码可以在这里找到:http://quickcounters.codeplex.com/SourceControl/latest#QuickCounters_net2/WCFSupport/QuickCounters.Wcf/InstrumentedServiceAttribute.cs

In particular, look at the code for the AddHttpGetDispatcher() method.

特别是,请查看AddHttpGetDispatcher()方法的代码。