Why is REST-API not called without processing response (fire-and-forget)?

38 Views Asked by At

I call a REST-API with this code (from a SQLCLR-Trigger):

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
        request.ContentType = "application/json; charset=utf-8";
        request.Method = "POST";

        using (var streamWriter = new StreamWriter(request.GetRequestStream())) {
            var json = ... // create json

            streamWriter.Write(json);
            streamWriter.Flush();
        }

        var httpResponse = (HttpWebResponse)request.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
            var result = streamReader.ReadToEnd();
        }

This is working. But when I remove the last three Lines (processing the response), the REST-API will never be called.

I want to call the API in a fire-and-forget way so the Trigger (which is calling the REST-API in fact) will not be blocked. Is this possible?

0

There are 0 best solutions below