简体   繁体   English

启动后但上载请求有效负载之前,如何拦截(服务器端)非流HTTP WCF请求

[英]How to intercept (server side) a non-streaming HTTP WCF request after it is started but before the request payload is uploaded

I have WCF clients that are making some large HTTP Post requests from some potentially slow connections. 我有WCF客户端,它们从某些可能较慢的连接发出一些大的HTTP Post请求。 I want to do some server side work on those requests as soon as I know the URI and QueryString of the request but before the payload actually finishes uploading. 我想在知道请求的URI和QueryString之后但在有效负载实际完成上传之前对这些请求进行一些服务器端工作。 The requests are non-streaming. 请求是非流式的。

My understanding is that the AfterReceiveRequest method of IDispatchMessageInspector gets called after the request has been fully received so that doesn't work. 我的理解是IDispatchMessageInspector的AfterReceiveRequest方法在完全接收到请求后被调用,因此无法正常工作。

Is this even possible in WCF? 在WCF中甚至可能吗?

You are right that the message would have been received, but you can still operate or replace the the message in the AfterReceiveRequest. 没错,消息已经收到,但是您仍然可以在AfterReceiveRequest中操作或替换消息。

AfterReceiveRequest is invoked by the dispatcher when a message has been received, processed by the channel stack and assigned to a service, but before it is deserialized and dispatched to an operation. 当消息已被接收,由通道堆栈处理并分配给服务时,但在反序列化并分配给操作之前,由分配器调用AfterReceiveRequest。 If the incoming message was encrypted, the message is already decrypted when it reaches the message inspector. 如果传入消息已加密,则到达消息检查器时,消息已被解密。 The method gets the request message passed as a reference parameter, which allows the message to be inspected, manipulated or replaced as required . 该方法获取作为参考参数传递的请求消息,从而可以根据需要检查,操作或替换消息

It seems you'd prefer to do something server side, but you can also implement the IClientMessageInspector.BeforeSendRequest to inspect and operate on the message just before it is sent out to the server. 似乎您希望在服务器端做一些事情,但是您也可以实现IClientMessageInspector.BeforeSendRequest以在将消息发送到服务器之前对其进行检查和操作。

BeforeSendRequest is invoked when the message has been composed either by the client application or by the operation formatter. 当消息由客户端应用程序或操作格式化程序编写时,将调用BeforeSendRequest。 As with the dispatcher message inspectors, the message can just be inspected or entirely replaced. 与调度程序消息检查器一样,可以仅检查消息或完全替换消息。

MSDN Documentation MSDN文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM