如何在WCF中拦截反序列化后的请求对象

发布于 2024-11-17 12:01:29 字数 356 浏览 7 评论 0原文

我需要拦截我们所有 Web 服务的 WCF 请求。所有服务都遵循严格的模型,其中操作必须接受从我们的基本请求类型扩展的单个请求。该基本请求类型携带我们需要的各种系统级支持的属性,自定义日志记录就是其中之一,但还有许多其他属性。我希望使用 IDispatchMessageInspector,但我不知道如何从“消息”获取请求对象,而无需从正文重新创建副本。我需要它是高效的,所以每个请求创建两个副本不会减少它。

我知道我可以使用 System.Reflection.Emit 创建代理,但这会与服务激活和工厂混淆......我希望有更容易获得的东西,比如 CXF 拦截器为 Java 工作的方式。

无论如何,我可以在分派到服务实现之前拦截服务器中的实际单个请求实例吗?

I need to intercept WCF requests for all of our web services. All of the services follow a strict model where the operations must take a single request that extends from our base request type. That base request type carries attributes we need for various system level support, custom logging is one, but there are many others. I was hoping to use IDispatchMessageInspector, but I don't see how I can get the request object from the "message" without having to recreate a copy from the body. I need this to be efficient, so creating two copies each request won't cut it.

I know I can create proxies with System.Reflection.Emit, but that'll get mixed up with service activation and factories...i was hoping for something more readily available, like the way CXF interceptors work for Java.

Is there anyway I can intercept the actual single request instance in the server, just before being dispatched to the service impl?

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

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

发布评论

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

评论(1

绿光 2024-11-24 12:01:29

消息检查器用于处理消息而不是参数。要使用反序列化对象,您需要参数检查器(实现 IParameterInspector)。

Message inspector is for working with messages not with parameters. For working with deserialized objects you need parameter inspector (implements IParameterInspector).

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