3
votes

I am using Visual Studio 2008 and have added a web reference that points to a WCF web service. Visual Studio has generated a client class automatically, so all I need to do to call the web service is to create an instance of the client and call the method on it.

FoodPreferenceServiceClient client = new FoodPreferenceServiceClient(); 
FoodPreferenceServiceResponse = client.GetFoodPreference();

The FoodPreferenceServiceClient is the web service client that is automatically generated by VS. The GetFoodPreference is the method on the web service that I am calling.

My problem is that I want to expose the actual HTTP header received in the above call, such as client.GetHttpResponse() or something.

Is there a way to do this?

2
I don't know what you're trying to do, but you might want OperationContext.IncomingMessageHeaders instead for custom properties.Rup

2 Answers

2
votes

Yes it should be possible. Try:

using (var scope = new OperationContextScope())
{
    var client = new FoodPreferenceServiceClient(); 
    response = client.GetFoodPreference();

    var httpProperties = (HttpResponseMessageProperty)OperationContext.Current
                             .IncomingMessageProperties[HttpResponseMessageProperty.Name];

    var headers = httpProperties.Headers;
    // Now you should be able to work with WebHeaderCollection and find the header you need
}
0
votes

you can't get the message headers through OeprationContext directly in client side, but you can develop a custom IClientMessageInspector, and in the interface you can get he SOAP XML message.