我们需要在没有回复的情况下记录请求(在超时的情况下)。我们正在使用 IClientMessageInspector 的实现来执行此操作。不幸的是,在第二种情况下没有调用 AfterReceiveReply - 当服务方法无效(不返回任何内容)时。有什么方法可以识别 BeforeSendRequest 方法中的 void 方法?
问问题
224 次
1 回答
0
没有漂亮的方法可以做到这一点,但我发现了一个丑陋的方法:)
/// <summary>
/// Checks internal operation formatter for action reply attribute which is empty for one way methods.
/// Based on above returns whether service method will have reply or not.
/// </summary>
/// <param name="request">Request message.</param>
/// <returns>Whether service method will have reply.</returns>
private bool WillRequestHaveReply(Message request)
{
FieldInfo operationFormatterField =
request.GetType()
.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(f => f.Name == "operationFormatter");
if (operationFormatterField != null)
{
object operationFormatter = operationFormatterField.GetValue(request);
if (operationFormatter != null)
{
PropertyInfo actionReplyProperty =
operationFormatter.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic)
.FirstOrDefault(p => p.Name == "ReplyAction");
if (actionReplyProperty != null)
{
return actionReplyProperty.GetValue(operationFormatter) != null;
}
}
}
// Every request should have operationFormatter inside.
// Use standard behaviour (requests with replies) if it doesn't.
return true;
}
于 2015-03-19T15:52:30.143 回答