Search code examples
c#web-serviceswcfsessionsetcookie

Getting an exception while trying to reach value of the "Set-Cookie" key in C#


I want to reach HTTP / SOAP Header of the response (note that, response is an object, not an xml string) coming from wcf service to get value of "Set-Cookie" key on response. I tried to use HttpResponseMessageProperty to get header but it throws an exception called ArgumentException.

In an ASP.NET example, WebRequest and WebResponse is working well but I am trying to write a library in C# with using proxy methods of the wcf service and because of that, I should use the HttpResponseMessageProperty.

Waiting your helps. Thanks.

Edit:

I attached a screenshot of the exception in below.

enter image description here


Solution

  •         using (OperationContextScope scope = new OperationContextScope(Parameters.ClientService.InnerChannel))
            {
                var response = Parameters.ClientService.SearchFlight(Parameters.AuthenticationHeader, Operations.CreateSearchRequest(fsf));
    
                var messageProperty = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
                var sessionId = messageProperty.Headers["Set-Cookie"];
    
                FlightSearchResultDto result = Operations.CreateSearchResult(response, fsf, BaseProvider);
    
                return result;
            }