0
votes

I'm getting some odd behaviour for a .NET 2.0 Webservice that uses a legacy COM object. Here's the scenario:

There are 2 client applications, the first application calls my web service when it receives notification of an update. The second application polls and retrieves the records from my web service, uses my web service to identify if they need updating, and then calls the web service again to delete the processed record. If the record requires an update, the second tells the first that something's been updated and the first application fires the event which in turn calls my web service.

To break it down here's how it looks. Application #2:

client.Records <- WebService.GetRecords()

for each record in Records
  client <-> WebService.IdentifyRecord(record)
  Notify Application #1 that it's time to call my web service.
  client -> DeleteRecord()

Application #1: Gets notification from Application #2 and calls WebService.PerformUpdates(...)

So all of this can happen in parallel. That is, we could be moved on to the next record while the PerformUpdates method is executing.

Sorry for the long winded setup description (I know it's convoluted, I have no say in the matter)... here's the problem: My IdentifyRecord and PerformUpdates methods call a COM component, which in turn uses ADODB.Recordset. In my logging I notice there are multiple exceptions being thrown, but not for every record, may be 1 out of 10 records will throw an exception. The exception happens within the COM component (which, sadly, I can't get source for, so changing it is out of the question). Sometimes it's a BOF/EOF error for the recordset, other times it's a NULL reference error. And the real weirdness happens when I look at the stack trace. Let's say this is my code:

adodbRecordSet.MoveFirst()
while not (adodbRecordSet.Eof)
  rowInDataTable = myDataTable.NewRow()
  rowInDataTable.BeginEdit()
  rowInDataTable("ID") = adodbRecordSet.Fields("ID").Value
  rowInDataTable("Name") = adodbRecordSet.Fields("Name").Value
  rowInDataTable("Address") = adodbRecordSet.Fields("Address").Value
  --> rowInDataTable("OtherInfo") = adodbRecordSet.Fields("OtherInfo").Value <-- HERE is where the exception occurs!!!
  rowInDataTable("YetMoreInfo") = adodbRecordSet("YetMoreInfo")
  rowInDataTable.EndEdit()
  adodbRecordset.MoveNext()
  myDataTable.AddRow(rowInDataTable)
next

In the case of the NULL object exception, it happens inside the Fields collection.

I can't help but think if it really was a EOF/BOF error or whatever, then it would have manifested itself on the first line ("ID")?

So, all I can assume is that there's something going on with COM and the parallel calls to the web serivce. If I call the web service serially (each method after the other), it works like a champ. But if the client calls the web service using the event, this is what happens.

Can anyone shed any light on what's going on???

Thanks!

1

1 Answers

1
votes

If you're interoping with COM from ASP.NET, you will need to know something about the COM threading model of the component you're interacting with. Here's an article with some useful info.

Be aware that whatever threading model your COM component claims to support, this is just an assertion from the developer. Multithreading is hard, and many legacy COM components don't get it right.

If you don't have access to the source or support for the COM component, you might have to resort to using locking to serialize accesses.