Sorry this is a bit of a repost of a question I have previously had answered, however the answer doesn't quite fit what I need so have reworded.
I'm developing an app which will be deployed across various platform including Windows Phone. Because of this, I only have access to the WCF Compact / Portable classes.
I need to be able to catch every outgoing request and incoming response in order to append headers to the request, and read the headers from the response.
When extending standard WCF I am able to achieve this using a custom behaviour, however in WCF compact this is not supported, so, I am able to use the following code to append headers to a specific request:
CalculatorServiceClient client = new CalculatorServiceClient();
using(new OperationContextScope(client.InnerChannel))
{
// We will use a custom class called UserInfo to be passed in as a MessageHeader
UserInfo userInfo = new UserInfo();
userInfo.FirstName = "John";
userInfo.LastName = "Doe";
userInfo.Age = 30;
// Add a SOAP Header to an outgoing request
MessageHeader aMessageHeader = MessageHeader.CreateHeader("UserInfo", "http://tempuri.org", userInfo);
OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader);
}
However, I'm not able to catch the response headers in this example. I'm also worried that this isn't thread safe (where multiple requests could be happening at the same time via the await/async pattern). And, finally I'd like to implement this functionality in a way that is transparent to the developer - so that they don't need to do anything special their code. I think I should be able to achieve it using something along the lines of a IClientMessageFormatter, however I'm at a loss as to how to implement this in WCF compact.
I'm hoping somebody might have an example of doing this, or something similar (a custom message encoder / encryptor maybe)?
Any help would be greatly appreciated.
Thanks David