无法在 ASP.NET 中使用 WCF NetPeerTcpBinding?
我为网络场编写应用程序,我想在服务器应用程序之间创建一个简单的对等网络,以便它们可以相互传递消息。例如,在删除缓存项时进行协调,或者增加共享计数器以获得关键统计数据的更好共享视图。
但显然这是不可能的。我的点对点代码在控制台应用程序中完美运行,但是当我将代码添加到 ASP.NET 网站时,出现以下错误:
当前上下文不支持系统事件通知。例如,服务器进程可能不支持全局系统事件通知。
[InvalidOperationException: System event notifications are not supported under the current context. Server processes, for example, may not support global system event notifications.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10259418
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +539
// My code here where I call the proxy object's method to start the WCF call
嗯,为什么不呢?看来这个功能非常有用啊!
有什么办法可以解决这个问题吗?
I write applications for web farms and I wanted to create a simple peer network between server applications so they could pass messages to each other. For example, to coordinate when dropping cache items, or to increment a shared counter to have a better shared view of a crucial statistic.
But apparently this isn't possible. I had peer-to-peer code working perfectly in a console application, but when I added the code to an ASP.NET website I got the following error:
System event notifications are not supported under the current context. Server processes, for example, may not support global system event notifications.
[InvalidOperationException: System event notifications are not supported under the current context. Server processes, for example, may not support global system event notifications.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +10259418
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +539
// My code here where I call the proxy object's method to start the WCF call
Um, why not? It seems like this would be supremely useful!
Is there any way to get around this?
您的服务运行在哪个版本的 IIS 上(假设是 IIS)? IIS 6 比 IIS 7 有相当多的限制 - 它仅支持 HTTP 激活。同样,如果您尝试从 IIS 6 中启动对等客户端,它可能会因同样的原因而被阻止 - IIS 无法将响应定向到正确的工作进程。
您始终可以将该服务实现为 Web 服务器上的 Windows 服务,并使用命名管道与 ASP.NET 站点进行通信。 (Windows 服务将托管一个对等端点和一个命名管道端点,站点将使用命名管道客户端。该服务将使用 [ServiceBehavior] 属性作为单个实例运行。
What version of IIS is your service running on (assuming IIS)? IIS 6 is quite a bit more limited than IIS 7 - it only supports HTTP activation. Likewise, if you're trying to start a peer-to-peer client from within IIS 6, it may be blocked for the same reason - IIS can't direct responses to the correct worker process.
You could always implement the service as a Windows service on the web server, and use named pipes to communicate with your ASP.NET site. (The Windows service would host a peer-to-peer endpoint and a named-pipe endpoint, and the site would use a named-pipe client. The service would run as a single instance using the [ServiceBehavior] attribute.