mjj
mjj

Reputation: 53

How to I set the Connection : Keep-Alive header to Close in the JsonServiceClient?

On occasion (not consistently), I'm receiving a "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server" exception thrown by an instance of the JsonServiceClient. I want to set the Http Connection Header to Close.

When I attempt client.Headers["Connection"] = "Close"; "I get a The 'Connection' header must be modified using the appropriate property or method.\r\nParameter name: name" exception.

Upvotes: 1

Views: 1399

Answers (2)

THINESH VASEE
THINESH VASEE

Reputation: 44

you can Just use this to close the connection {Connection: close};

Upvotes: 0

mythz
mythz

Reputation: 143379

You can set the HTTP Request Connection header using a Request Filter, e.g:

var client = new JsonServiceClient {
    RequestFilter = req => req.Connection = "Close"
};

Upvotes: 1

Related Questions