1

using a Webrequest within a script task to consume a Rest Service

I get the following error

A connection that was expected to be kept alive was closed by the server

I'm calling the rest service within a For Each Loop container. It works the first time but not any subsequent executions.

searching stack overflow I've come across the following settings tha have helped others but not me

ServicePointManager.Expect100Continue = false;
ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.MaxServicePointIdleTime = 5000;

I'm thinking it's because the KeepAlive property is set to true but I can't see a way to change it and it isn't a property that can be changed

enter image description here

Geezer
  • 513
  • 5
  • 17

1 Answers1

1

you can cast

HttpWebRequest req = WebRequest.Create("https://www.server.com/api/stuff") as HttpWebRequest;

req.KeepAlive = false;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();

or override

internal class MyWebClient : WebClient
{
    override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest req = (HttpWebRequest)base.GetWebRequest(address);
        req.KeepAlive = false;

        return req;
    }
}

your WebRequest to access further properties that are hidden or abstracted!

Falco Alexander
  • 3,092
  • 2
  • 20
  • 39