My AfterRecieveRequest method generates a GUID, and passes this on through the correlationState variable to the BeforeSendReply method.
Between those two calls, a lot happens in my WCF service, and I'd like to access this GUID from within the Webservice methods. Is there a way for me to access this object throughout the WCF service?
The GUID is used for logging purposes, as I am calling on the API of a different application and want to log the results, and log them under the GUID generated in the IDispatchMessageInspector implementation.
for example:
IDispatchMessageInspector implementation:
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
var correlationState = GUID.NewGuid();
StaticLogger.AddLog(originalMessage, correlationState.ToString(), "WCF-Incoming");
return correlationState;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
StaticLogger.AddLog(originalMessage, correlationState.ToString(), "WCF-Outgoing");
}
WCF Service:
public ResponseObject WCFMethod(string param1, string param2)
{
ResponseObject response = new ResponseObject();
Client client = new Client();
ClientObject result = client.OutsideOperation(param1,param2);
// here, i would like to log the result object and use the GUID from the correlationstate
StaticLogger.AddLog(result, correlationState.ToString(), WCF-Internal )
response.resultAttribute = result;
return response;
}
How would I go on to accomplish this? I've been thinking about using a ThreadStatic attribute so the thread keeps the GUID somewhere in memory, but I am afraid my understanding of this subject is insufficient to implement it right now.