[Solved] How do I obtain a response header value when making a REST call via WCF?
The simplest way is to change the interface declaration such that the method returns System.ServiceModel.Channels.Message
:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = @"whatever")]
Message CoolMethod(InputContainer input);
then once method invokation is complete you get a Message
object which contains the HTTP response with the headers:
var invokationResult = service.CoolMethod( new InputContainer() );
var properties = message.Properties;
var httpResponse =
(HttpResponseMessageProperty)properties[HttpResponseMessageProperty.Name];
var responseHeaders = httpResponse.Headers;
var coolHeader = reponseHeaders["x-some-cool-header"];
Read more here: Source link