I have a WCF service which includes UI components, which forces me to be in STA mode.
How do I set the service behaviour to STA-mode?
I have a WCF service which includes UI components, which forces me to be in STA mode.
How do I set the service behaviour to STA-mode?
I would investigate using the [STAThread] attribute to switch the threading model. e.g.
[STAThread]
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Host() };
ServiceBase.Run(ServicesToRun);
}
Description of the STAThread attribute
But I'm confused why you're using UI components in a web service at all. Can you explain a bit more about why you're trying to do this?
The service uses a reference to a wpf dll which opens a ui window(used as view port) for picture analycies. When the service is trying to create an instance of that item(inherits from window) it throws an exception: The calling thread must be an STA
I'm doing something similar to you.
My solution was to route all calls through an STA thread queue. I used a threadsafe collection from the new parallel framework to queue up Actions I wanted to run on a STA thread. I then had X number of STA threads that continually checked the queue for new actions to execute.
Try this article (WCF STA Threads), provides very clear instructions(and code) for using WCF and STA Threads.
It explains how to create a WCF behaviour to allow WCF operations to run in a STA thread.