Curiosity!

I was testing to see what happens when you try to open a windows form in a web service (when run from the server machine or a client one), which I knew was wrong - but I wanted to see what happens, you know!

The web method:

[WebMethod()]
public void ShowMainForm()
{
    new MainForm().ShowDialog();
}

Not surprisingly, running this method from another machine (other than the web server) results in the exception “System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation.”, same as when running the deployed web service through a browser.

What is strange is that it works fine when the service is launched from the Visual Studio Debugger (F5 | Ctrl+F5) - can’t say “fine” but it shows the form and there’s no exception.

I searched a bit and it is written everywhere that doing such a thing is not possible and is against the client/server architecture. I mean if it’s that bad, not standard and not logical, why should Visual Studio let it run (actually make it run) properly?

Mahdieh

Tags: , ,

Leave a Reply