我正在尝试记录来自我的 WCF 服务的请求和响应。到目前为止我所做的是:
public class OutputMessageInspector : IDispatchMessageInspector
{
int lastLogId;
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
// Parse request & read required information
// Insert request data into log tables
// Set lastLogId to the id created above
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
// Parse reply
// Using lastLogId update the response column in database table
}
}
一切正常,但我有一个担忧:
AfterReceiveRequest
并且BeforeSendReply
必须同步工作,以便BeforeSendReply
更新正确的记录。我想到的情况是同时从多个客户端调用服务,问题:
- 不会
lastLogId
在多个请求和响应之间搞砸和洗牌吗? - 此日志记录特别更新
BeforeSendReply
会与多个客户端同时调用服务正常工作吗?如果是,那么请给我一个解释,以确保我的想法,如果不是,那么请为此提供更好的解决方案。