I send a message from my client (implements IClientMessageInspector) using BeforeSendRequest() and receive the reply from the endpoint at AfterReceiveReply().
My question is what is the most effective way to "validate" the reply that I receive is in relation to the request I sent?
I found some article about using the correlationstate, but the examples were all too vauge.
Any help is greatly appreciated.
As far as I know, we could use the Correlationstate
parameter to maintain the value in order to represent the relativity.
That’s why the BeofreSendRequest
has the returned value.
public void AfterReceiveReply(ref Message reply, object correlationState)
{
Console.WriteLine(correlationState.ToString());
string displayText = $"the client has received the reply:\n{reply}\n";
Console.Write(displayText);
}
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
var correlationstate = Guid.NewGuid().ToString();
string displayText = $"the client send request message:\n{request}\n";
Console.WriteLine(displayText);
return correlationstate;
}
Here is a related discussion, wish it is useful to you.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/c8de85bf-9ffe-478e-a23c-2514a6504bce/iclientmessageinspector-maintain-id-value-between-the-beforesendrequest-and-afterreceivereply?forum=wcf
Feel free to let me know if there is anything I can help with.