ServiceHost消息接收事件?

发布于 2024-08-03 11:55:52 字数 494 浏览 1 评论 0原文

在 ServiceHost 或 Channel 或 Dispatcher 处理消息之前,肯定必须附加一个事件吗?我假设它可以通过 OperationContext.Current 访问,但我能找到的最接近的事件是 Opening 和 Closing。是否有类似 MessageReceived 或 BeforeMessageProcessed 事件的事件?

如果不使用事件,是否有其他方法使用 WCF 类/配置来确定 ServiceHost SingletonInstance 当前是否正在处理 DataContract?

编辑:IDispatchMessageInspector(AfterReceiveRequest 和 BeforeSendReply)非常完美。我有大约 8 个服务,需要知道它们当前正在处理哪些消息(DataContracts)。虽然可以使用类似辅助方法的方法,该方法接受委托并执行 BeforeReceive();调用委托();接收后();使用 IDispatchMessageInspector 和行为要容易得多。

Surely there must be an event to attach onto before a ServiceHost or Channel or Dispatcher handles a message? I'm assuming it can be accessed through OperationContext.Current, but the closest events I can find are Opening and Closing. Is there something like a MessageReceived or BeforeMessageProcessed event?

If not using events, is there some other way using WCF classes/configuration to determine if a ServiceHost SingletonInstance is currently processing a DataContract?

EDIT: IDispatchMessageInspector (AfterReceiveRequest and BeforeSendReply) is perfect. I have about 8 services and need to know what messages (DataContracts) they are currently processing. While it would be possible to use something like a helper method that takes a delegate and does BeforeReceive(); InvokeDelegate(); AfterReceive(); it's far easier to use IDispatchMessageInspector and behaviors.

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

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

发布评论

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

评论(1

原野 2024-08-10 11:55:52

据我所知,服务主机级别没有直接发生这样的事件。您能解释一下您想要实现的目标吗?

通常,如果您在消息到达时必须执行任何处理,那么正确的方法是使用 WCF 为此提供的几个扩展点之一,例如 IDispatchMessageInspector。在这种情况下,您可以通过 服务或端点行为

As far as I know, there isn't such an event at the service host level directly. Could you explain what you're trying to accomplish?

Normally, if you've got any processing that must be done whenever a message arrives, then the right way is to use one of the several extensibility points that WCF offers for this, like IDispatchMessageInspector. In this case, you'd inject your message inspector into the WCF pipeline through a service or an endpoint behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文