简体   繁体   中英

COM Object in WCF Service

My WCF Service, written in .NET 4.0, has a problem that the second, or any other call get stuck. The WCF Service does nothing else than calling a COM Object written in Delphi XE. The threading model is set to Both, the InstanceContextMode of the service is set to PerCall. The object does not much more than BSTR DoRequest(BSTR Request). I use Marshal.ReleaseComObject, but read in an article this is not a good way to clean up com objects; i tried it also without.

I tried the following things:

  • added logging to see where the WCF service is stuck. It is inside the COM call.
  • added a unhandled exception handler, but there are no exceptions.
  • checked if the Delphi Object uses Static variables
  • tried to compile with Delphi XE2 (maybe a bug in the delphi com libraries)
  • tried the Object with a multithreaded Delphi stress test tool to see if the problem is the same, but it worked nicely.
  • tried the object with a C# console stress test tool and got the same behaviour as in the WCF Service.
  • added a lock object around creating the Object, doing the call and destroying the Object. This did not help.
  • tried to create a new thread inside the WCF and set the threading model to STA; set the Delphi Object Threading Model to Single. This did not help.
  • tried to run the Object in the COM+ Services; this did not help.
  • checked the WCF throttling, this is set to 100
  • checked max connections of the service and set to MaxInt

the COM DLL is 32 Bit, so my VStudio Project Settings restrict to x86. I run on Windows 2008 R2. Maybe this does matter: The Delphi COM Object loads a C++ DLL, which might not be treadsafe.

I used Reflector + Dennis Bauer FileDisassembler to decompile the generated COM Wrapper. I dont see any special in it.

Using Windebug seems not very easy, as Delphi does not support PDB Files.

running out of ideas, please help :-)

I added a critical section around all calls to the third party dll inside the delphi code. It looks like it is working now. This does not explain the behaviour of the com object, but now it seems to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM