I'm calling a web service using an HTTPWebRequest. I do this in a variety of ways, but the code is always the same. One of the methods validates records against the API. A different method uses POST to upload a record. The code for these two is identical except that there is one Boolean added to the header of the validation record. The reason this works is that the validation is run on anything received from either method, but if the flag is absent, then the API method goes ahead and writes the record to the DB if it passes validation. If the flag is present, then the API method doesn't write the record to the DB.
Whenever I validate the records, all is well. There could be dozens of records, and this has been tested repeatedly and has never had a problem. When I upload, the first record works fine, the second record times out. Since the code between the two methods is identical other than the Boolean, I'm thinking this isn't happening on my end, but the API writer doesn't see anything happening on their end, either.
To make matters worse, when I upload a record, there is one call to the API to see whether the record is in the DB, as I use a PUT if the record already exists, and a POST if it doesn't. This initial call is a GET, and has no JSON payload, but is otherwise the same as the validation, or either form of the upload (PUT or POST, though it doesn't matter which is used in this problem).
The code where it hangs is in here:
The line in red is where the timeout happens. My understanding is that GetRequestStream opens a connection with the API, so the problem seems to be in that connection step, but doesn't have anything to do with the database activity on the other end, since I timeout before even getting to the line where I write.
One other point to note is that this program has been working for months, and this issue was just found yesterday. That doesn't mean that the problem arose yesterday, as the program is only used every couple months, but I'm pretty sure that it was working correctly in November.
Any suggestions of things to look at would be appreciated.
Whenever I validate the records, all is well. There could be dozens of records, and this has been tested repeatedly and has never had a problem. When I upload, the first record works fine, the second record times out. Since the code between the two methods is identical other than the Boolean, I'm thinking this isn't happening on my end, but the API writer doesn't see anything happening on their end, either.
To make matters worse, when I upload a record, there is one call to the API to see whether the record is in the DB, as I use a PUT if the record already exists, and a POST if it doesn't. This initial call is a GET, and has no JSON payload, but is otherwise the same as the validation, or either form of the upload (PUT or POST, though it doesn't matter which is used in this problem).
The code where it hangs is in here:
Code:
Dim upRequest As HttpWebRequest = DirectCast(WebRequest.Create(someURI & PK.ToString & ".json?XApiKey=" & TRUEAPIKEY.ToString), HttpWebRequest)
upRequest.Method = "PUT"
upRequest.ContentType = "text/json"
upRequest.Credentials = cred
Dim swrite As StreamWriter = New StreamWriter(upRequest.GetRequestStream)
swrite.Write(jsonString)
swrite.Flush()
swrite.Close()
One other point to note is that this program has been working for months, and this issue was just found yesterday. That doesn't mean that the problem arose yesterday, as the program is only used every couple months, but I'm pretty sure that it was working correctly in November.
Any suggestions of things to look at would be appreciated.