ListenSecure Exception

Problem: Achieving Dicom Server security in .NET using Activex DicomObjects component

I've implemented QueryServer as a windows service in .NET. When I tried to listen to a secured port using ListenSecure method of the DicomServer a COM Exception "Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)" is thrown.

In order to fix this exception, the entry point of your Windows service should be decorated with STAThread to force it to run in a single threaded apartment. Alternately, the method which does the server initialisation can be decorated with "STAThread" attribute.

       // Entry Point for the Query Server
       public static void Main()

Windows service generally runs under MTA and STA attribute being used only to initialise the service. However there will be other sporadic threading problems with callbacks using an ActiveX Component from windows service. Callbacks coming back to windows service which are MTA need to be marshalled to the STA thread. Hence Windows messages need to pumped and windows services are not able to pump the messages queue.


Alternate Solutions:

Move the entire Query server code to a winforms application which is designed for pumping windows messages. Instantiate the server from windows query service. Thus the Winforms application runs as a daemon.

--Venumadhav 03:36, 26 September 2010 (UTC)