HttpWebRequest Timeout updating status Code in BigCommerce

95 views Asked by At

I have read a lot, if not all the posts, on timeouts for web requests and the solutions provided have not worked. I am getting orders from Big Commerce and then updating the Big Commerce status code. I can update 2 orders and then I timeout on the third, every single time regardless of day of week or time of day.

App.Config file has:

```
<system.web>
    <httpRuntime executionTimeout="180" />
</system.web>
```

Code:

```
    Try
        Dim strJSON As String = "{""status_id"": 9}"
        Dim postBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(strJSON)
        For i As Integer = 0 To dto.Rows.Count - 1
            strWebOrder = dto.Rows(i).Item("WebOrder")
            Dim strHttp As String = "https://api.bigcommerce.com/stores/storeid/v2/orders/" & strWebOrder
            Dim request As HttpWebRequest = DirectCast(WebRequest.Create(strHttp), HttpWebRequest)
            request.Accept = "application/json"
            request.ContentType = "application/json"
            request.Headers("X-Auth-Token") = strAuthToken
            request.Timeout = 10000
            request.AllowWriteStreamBuffering = False
            request.SendChunked = True
            request.Method = "PUT"
            Dim postStream As Stream = request.GetRequestStream()
            postStream.Write(postBytes, 0, postBytes.Length)
            Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            If response.StatusCode = 200 Then
                strErrorRef = "Web " & strWebOrder
                strErrorReason = "Order Status Changed to Exported"
                strPutMessage = ""
                WriteError()
            Else
                strErrorRef = "Web " & strWebOrder
                strErrorReason = "Unable to change Web Order Status to Exported"
                strPutMessage = ""
                WriteError()
            End If
        Next
    Catch ex As Exception
        strErrorRef = "Web " & strWebOrder
        strErrorReason = "Unable to change Web Order Status to Exported"
        strPutMessage = (ex.ToString)
        WriteError()
    End Try
```
1

There are 1 answers

4
Heather Barr On

Have you tried to increase the seconds in your executionTimeout property? If you increase it to 300, this will give your application 5 minutes to execute the command before it’s shut down, rather than the 3 minutes you’re currently using.

I’m not sure what all you’ve tried or read into, but it sounds like the code you have is taking at least 2-3 minutes to get through 2 orders, so that’s why the result you see is the same regardless of the time of day it’s being executed.

Have you tried to refactor the code to break it up a bit, for example: grab all orders with status_id 9 in one function OR store these order_ids in an array in another function elsewhere, then in a new function loop through the stored array to update the status_id?

Also, are you using webhooks at all?