3

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 apped 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). 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 requests. 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.

Any help would be greatly appreciated.

Thanks David

DavidReid
  • 449
  • 1
  • 5
  • 21

0 Answers0