什么可能导致 WCF NamedPipe 通道出现故障(在服务器端?)

发布于 2024-12-05 00:35:46 字数 1490 浏览 0 评论 0原文

如果这看起来有点基础,我深表歉意,但我对 WCF 很陌生,而且对一般的进程间通信也很陌生。

我的设置详细信息

我在 WCF“服务器”中使用 NetNamedPipeBinding,它是作为 Windows 服务运行的应用程序的一部分。

我有两个客户端使用 DuplexChannelFactory 创建的通道与 WCF 服务器进行通信。一种是 ASP.Net MVC 3 Web 应用程序,它针对每个页面请求创建一个通道(然后关闭它**)。另一个是 WPF 应用程序(用作服务的一种监视控制台/诊断工具)。

一切都运行良好 - 通常持续一周或更长时间 - 有很多人访问 Web 应用程序,但只是偶尔 WCF“服务器”内部出现问题,并且客户端开始报告异常“通信对象,System.ServiceModel.Channels。服务渠道, 每当他们尝试创建通道代理时,“无法用于通信,因为它处于故障状态”。

一旦服务器“故障”,每次尝试连接都会导致该错误。即使是控制台应用程序的新实例也会报告该错误。让我相信这不是“客户端”端的问题。

** 注意:我认为通道会随着每个页面请求而关闭,它会被实例化为 MVC 控制器的成员。我的知识超出了范围并在最后处理掉也许我错了?

问题:

有人对在哪里查看有任何建议吗?甚至我如何在我的测试环境中重现此问题?

可以完全消除这种情况吗?或者我应该在“服务器”内设置一个线程,每隔几分钟尝试连接到命名管道服务,并在失败时重新启动该服务。

包含我正在使用的代码

可能会有所帮助(在 WCF“服务器”中)监听指定服务器上的请求管道

host = new ServiceHost(
    this,
    new Uri[] {
        new Uri("net.pipe://localhost")
    }
);
host.AddServiceEndpoint(
    typeof(IStationDirectory),
    new NetNamedPipeBinding(),
    "StationDirectory"
);

host.Open();

/* Some logging code here */


Thread.Sleep(Timeout.Infinite);

更多问题

假设我正确理解每个 NamedPipe“通道”实际上与 TCP 连接相同(对于每个客户端/服务器对来说都是唯一的)。如果我不断看到新客户端出现通道故障错误,那么可能客户端创建的每个新通道从一开始就以某种方式损坏。这是否意味着故障发生在 ServiceHost 内部的某个地方?在这里捕获 host.Faulted 事件有什么好处吗?

决议更新(2013)

我知道自从我问这个问题以来已经很长时间了 - 但我只是在我的历史中注意到它,所以我想我应该补充一点,尼克已经击中要害。我认为是消息有效负载大小导致了问题。消息中包含“报告”对象列表,每个对象都链接到上一个报告。随着时间的推移,这个名单会越来越长。删除旧报告并将 WCF 消息保持在或多或少固定的大小可以阻止错误。该应用程序在过去几年中一直运行非常可靠。

I apologise if this seems a little basic, but I'm new to WCF - and also to interprocess communication in general.

Details of my Setup

I'm using a NetNamedPipeBinding in my WCF "server", which is part of an application that runs as a windows service.

I have two clients that communicate with the WCF server, using a channel created by a DuplexChannelFactory. One is an ASP.Net MVC 3 web application, which creates a channel (and then closes it**) with each page request. The other is a WPF application (used as a sort of monitoring console / diagnostic tool for the service).

Everything runs along fine - often for a week or more - with lots of people accessing the web application, but just occasionally something breaks inside the WCF "server" and the clients begin reporting an exception "The communication object, System.ServiceModel.Channels.ServiceChannel,
cannot be used for communication because it is in a Faulted state" whenever they try to create a channel proxy.

Once the server "faults", every attempt to connect results in that error. Even new instances of the console application will report it. This leads me to believe it's not an issue at the "client" end.

** NOTE: I think the channel is closed with each page request. It is instantiated as a member of the MVC controller, which to my knowledge falls out of scope and is disposed at the end of the request. Perhaps I'm wrong?

The Question(s):

Does anyone have any suggestions on where to look - and even how I might be able to reproduce this issue in my test environment.

Can this sort of thing be eliminated entirely? Or should I resort to having a thread inside the "server" which attempts to connect to the named pipe service every few minutes and restart the service if it fails?

Addtional Information

It may be helpful to include the code that I'm using (in the WCF "Server") to listen to requests on the Named Pipe

host = new ServiceHost(
    this,
    new Uri[] {
        new Uri("net.pipe://localhost")
    }
);
host.AddServiceEndpoint(
    typeof(IStationDirectory),
    new NetNamedPipeBinding(),
    "StationDirectory"
);

host.Open();

/* Some logging code here */


Thread.Sleep(Timeout.Infinite);

More Questions

Assuming I understand correctly each NamedPipe "Channel" is effectively the same thing as a TCP connection (unique to each client/server pair). If I keep seeing the channel faulted error with new clients, then presumably every new channel that is being created by clients is somehow broken from the start. Does this mean that the failure is somewhere inside the ServiceHost? Would there be any benefit in catching host.Faulted events here?

Update on Resolution (2013)

I know it's been a very long time since I asked this question - but I just noticed it in my history here on SO and I thought I should add that Nick had hit the nail on the head. I believe it was the message payload size that was causing the problem. Included in the messages were a list of "report" objects, that each linked to the previous report. Over time this list would grow. Pruning off the old reports and keeping the WCF messages at a more-or-less fixed size stopped the faults. The application has been running very reliably for the last couple of years.

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

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

发布评论

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

评论(1

忆沫 2024-12-12 00:35:46

我首先进行一些 WCF 跟踪。

http://msdn.microsoft.com/en-us/library/ms733025.aspx

如果他们在您可以看到的任何地方(在事件查看器中)绝对没有记录任何事件,那么可能是

  1. 消息有效负载对于您的绑定来说太大。如果您返回大型结果集,并且它是间歇性的,我会从这里开始。还要检查您的 maxItemsInObjectGraph 绑定配置。
  2. 服务启动时出现未处理的异常。这似乎不是你的问题。

I'd start by doing some WCF tracing.

http://msdn.microsoft.com/en-us/library/ms733025.aspx

If they're faulting with absolutely no events logged anywhere you can see (in Event Viewer) then it's probably either

  1. Message payload is too big for your binding. If you're returning large result sets, and it's intermittent, I'd start here. Check your maxItemsInObjectGraph binding configuration as well.
  2. Unhandled exceptions on the service start. That doesn't seem to be your problem.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文