I have a web service, created using C#. For some reason, it seems to throw a 500 internal server error whenever I invoke my exposed method. I set some breakpoints and found the following line is what does it:
m_Browser = new WebBrowser();
Any idea why this line would cause my service to crash? The WebBrowser control is in the System.Windows.Forms namespace.
That’s probably because as the documentation clearly states it
while a web service runs in a multi thread apartment mode (MTA). This same article shows a hack that could be used to run your web service in an STA mode but the performance of doing so might decrease.
Clearly a
WebBrowsercontrol is not meant to be used in a web service but in a client application with a GUI. So usually when you are trying to use something into a scenario that this something is not meant for, there’s a price to pay.