跨应用程序域服务的多个实例 [英] Multiple instances of Service across AppDomains

查看:134
本文介绍了跨应用程序域服务的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想建立一个记录与多个AppDomain的应用程序。我想在内存中创建一个中央存储所有登录信息进入。我决定去与一个命名管道绑定WCF和我创建它创建了一个渠道,将所有日志事件的主要服务。

So I'm trying to set up a logger in an application with multiple AppDomains. I want to create one central store in memory for all logged messages to go into. I've decided to go with a WCF named pipe binding, and I've created a log4net appender which creates a channel and sends all log events to the main service.

问题是,我似乎得到每个应用程序域服务的新副本,因此我的单数最终被多个日志。

The problem is that I seem to get a new copy of the service in each AppDomain, and thus my single log ends up being multiple logs.

安装程序是我有一个服务合同接口, ILogSink ,和一个单(实际单,并InstanceContextMode设置为单在服务行为属性)的服务实现的 ResultLog 哪些有记录的消息的集合。在我的父母我的AppDomain实例的ServiceHost ResultLog ,然后打开服务。然后,我附上一个appender WcfResultAppender ,其中有一个代理副本 ILogSink 通过的ChannelFactory CreateChannel调用(该服务的主机地址)创建的。在启动时,每个孩子的AppDomain创建其自己的WcfResultAppender的副本。

The setup is I have a service contract interface, ILogSink, and a singleton (actual singleton, and InstanceContextMode set to Single in Service Behavior attribute) service implementation ResultLog which has a collection for the logged messages. In my parent AppDomain I instantiate ServiceHost with ResultLog, and Open the service. Then I attach an Appender WcfResultAppender, which has a proxy copy of ILogSink created via a ChannelFactory CreateChannel call (to the service host address). On startup, each child AppDomain creates its own copy of WcfResultAppender.

我是很新的WCF,我错过什么?

I'm very new to WCF, what am I missing?

编辑:我还没有收到任何答复好这个 - 我已经把这个问题放在一边,但它是一个pressing需要。看来,如果我得到我的服务类的不同的副本中的每个应用程序域,由于某些原因,数据被留在这些对象。我期望,有一些在使用的绑定来解决与主AppDomain中创建的服务,并通过该传递数据的背景,但别的东西正在发生。我已阅读WCF无数的解释和例子 - 有一件事我注意到的是没有的例子提供了哪些保留数据服务。不过,我仍然可以找到没有什么矛盾或证实我的期望。

I still haven't received any good responses to this - I've put the problem aside for now, but it is a pressing need. It seems as if I'm getting a different copy of my service class in each app domain, and for some reason the data is being left in those objects. I expected that there was something in the background that used the binding to resolve with the service created in the main appdomain and pass the data in via that, but something else is happening. I have read countless explanations and examples of WCF - one thing I noticed was none of the examples provide services which retain data. However I still can find nothing that contradicts or confirms my expectations.

推荐答案

每个AppDomain中是一个孤立的环境中,他们彼此之间没有直接的互动。

Each AppDomain is an isolated environment, they have no direct interaction with each other.

考虑暴露通过IIS服务或WAS将在自己的(单)的AppDomain运行它。

Consider exposing your service via IIS or WAS which will run it in its own (single) AppDomain.

请参阅 http://msdn.microsoft.com/en-us/library /ms733766.aspx 对于如何在IIS托管WCF服务的详细信息。

See http://msdn.microsoft.com/en-us/library/ms733766.aspx for details of how to host a WCF service in IIS.

请参阅 http://msdn.microsoft.com/en-us/library /ms733109.aspx 对于如何是主人WCF服务的详细信息。

See http://msdn.microsoft.com/en-us/library/ms733109.aspx for details of how to host a WCF service in WAS.

希望这有助于。

这篇关于跨应用程序域服务的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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