mrciga
mrciga

Reputation: 57

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

Upvotes: 0

Views: 126

Answers (2)

AltugCan
AltugCan

Reputation: 108

        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;
        }

Upvotes: 1

Galma88
Galma88

Reputation: 2546

I think the best way is to include that statement in a try 'n' catch statement and manage the exception.

Upvotes: 0

Related Questions