在 WCF REST 服务中记录请求/响应
我正在寻找一种在 WCF REST 服务中记录请求和响应的方法。 WCF REST 入门工具包附带了一个 RequestInterceptor 类,可用于拦截请求,但似乎没有对应的响应类。理想情况下,我希望能够在通过网络发送响应之前拦截响应,例如当底层服务方法返回时。有什么建议吗?
I'm looking for a way to log both requests and responses in a WCF REST service. The WCF REST starter kit comes with a RequestInterceptor class which can be used to intercept requests, but there does not seem to be an equivalent for responses. Ideally, I'd like to be able to intercept a response just before it's sent over the wire, e.g. when the underlying service method returns. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,如果您想拦截原始消息而不是参数,您可以注入 IDispatchMessageInspector 而不是 Dani 建议的 IParameterInspector 扩展点。
Notice that if you want to intercept the raw message, and not the parameters, you can inject your implementation of IDispatchMessageInspector instead of the IParameterInspector extension point that Dani suggests.
WCF中有一个技术:
您创建从 Attribute IOperationBehavior 派生的 InstrumentedOperationAttribute。
在你内部实现:
ServerPI() 类的神奇之处在于:
您可以在 beforecall 和 aftercall 方法中执行所需的所有操作:
There is a technic in WCF:
you create InstrumentedOperationAttribute that derives from Attribute, IOperationBehavior.
Inside you implement:
and the ServerPI() class is what does the magic:
you do everything you need in beforecall and aftercall methods: