Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wcf 将响应正文从IDispatchMessageInspector传递到应用程序_EndRequest_Wcf_Rest_Global Asax_Idispatchmessageinspector - Fatal编程技术网

Wcf 将响应正文从IDispatchMessageInspector传递到应用程序_EndRequest

Wcf 将响应正文从IDispatchMessageInspector传递到应用程序_EndRequest,wcf,rest,global-asax,idispatchmessageinspector,Wcf,Rest,Global Asax,Idispatchmessageinspector,我想记录通过我的WCF REST服务传输的请求参数和响应主体。我可以在IDispatchMessageInspector中访问完整响应。我可以在应用程序_EndRequest中的操作期间访问请求头和存储在Context.items中的其他项 在调试期间,我看到操作通过IDispatchMessageInspector,然后通过应用程序请求。我的想法是将响应存储在IDispatchMessageInspector中的某个位置,然后在Application_EndRequest中,检索响应并将其与其

我想记录通过我的WCF REST服务传输的请求参数和响应主体。我可以在IDispatchMessageInspector中访问完整响应。我可以在应用程序_EndRequest中的操作期间访问请求头和存储在Context.items中的其他项

在调试期间,我看到操作通过IDispatchMessageInspector,然后通过应用程序请求。我的想法是将响应存储在IDispatchMessageInspector中的某个位置,然后在Application_EndRequest中,检索响应并将其与其他请求参数一起记录


因此,我的问题是:我应该将响应存储在哪里,以便可以在应用程序中访问它?我目前正在尝试做类似的事情。我正在记录一个传入的请求,将其存储在数据库中,然后希望将日志ID传递给我的端点以供以后使用。在AfterReceiveRequest调用中,只需将所需内容添加到当前operationcontext的IncomingMessageProperties属性:

编辑:修复了下面的代码

public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {
        MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
        request = buffer.CreateMessage();
        int LogRequestID = Logging.LogIncomingRequest(buffer.CreateMessage());

        OperationContext.Current.IncomingMessageProperties.Add("LogRequestID", LogRequestID);

        return null;
    }
然后,我可以使用以下代码读取端点中的LogRequestID:

OperationContext.Current.IncomingMessageProperties["LogRequestID"]
如果需要,还可以传递更复杂的。希望有帮助