views:

162

answers:

3

I have a VB.NET web service that is calling a Interop COM object. When I make multiple calls to the web service at the same time, the web service processes fine until it gets to calling the first method of the COM object. At this point, it seems as though the calls to the COM object get put on a stack and they get processed on a FIFO basis. So, each web service call sits until the previous one has completed processing.

I have done the same thing on the console app side before with calling a class library that is using the COM library and you could run multiple console apps using the same Interop COM object at the same time with no problem.

What do I need to do in order to get this to work properly on the web services side? The web services should not have to wait for a COM to finish in a previous web service call in order to continue processing.

+1  A: 

Your multiple console instances are each their own process so they get their own copy of the COM object.

IIS and your web service are in a single process so you will be subject to the COM threading rules. It may be that the COM object you are using is marked single threaded. Or it implements a singleton pattern so that only one copy exists per process and it is apt threaded. Regardless for an apt threaded COM object only one thread can be accessing it at a time.

The rules around COM and threading are fairly complex, they COM object you are using may not have been written to work well under IIS.

Darryl Braaten
A: 

I'm of course, unfamiliar with the object you deal with, but just an idea: is it possible for you to proxy calls to the COM object through a COM+ application? This way you might be able to set desired threading model, also make it out-of-process (hosted in dllhost.exe), so IIS will not have to fight with it as in-process server

galets
A: 

Upon further investigation I have discovered that this is a problem with the web service running in the MTA apartment and the COM is in the STA appartment. This article explains it nicely... http://msdn.microsoft.com/en-us/magazine/cc163544.aspx and gives a solution, however, when I implement this it doesn't seem to move the web service to the STA apartment.