【发布时间】:2013-04-16 06:06:04
【问题描述】:
我在我的应用程序中实现了一个IClientMessageInspector 来“拦截”传出 Web 服务调用。是否可以从BeforeSendRequest 和AfterReceiveReply 内部找出正在调用的操作?
这里有一个类似的问题,How do i get the invoked operation name within a WCF Message Inspector,是针对服务端(接收请求的一方)。我试图做类似的事情,例如
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var v = OperationContext.Current.OutgoingMessageProperties["HttpOperationName"];
return null;
}
public void AfterReceiveReply(ref Message reply, object correlationState)
{
var v = OperationContext.Current.OutgoingMessageProperties["HttpOperationName"];
}
但在发出请求期间,OperationContext.Current 似乎为空,所以我不能使用它。知道如何得到它吗?知道如何干净地做到这一点(而不是说,解析 SOAP xml)吗?
【问题讨论】:
-
这很难,因为您在客户端堆栈中的位置非常低,以至于您真正需要的信息都包含在消息对象中。你有机会使用不同的检查员吗?例如,每个操作都会应用一个 IParameterInspector,因此是直截了当的。它还可以让您避免绑定特定的解决方案,例如 HTTPOperationName。
-
参数检查器如何工作?
标签: c# .net wcf soap iclientmessageinspector