I wrote a simple Windows Application based application in C# called the
CallWebServiceGui. This application is started from a different application
called WsGuiStarter. The WsGuiStarter redirects the standard input from the
CallWebServiceGui as a simple method for inter-process communication (IPC)
between the two applications. For the reason of IPC the CallWebServiceGui
creates a new thread, starts it and in it waits for input from standard input.
But if you do such a thing, every call to the WS proxy deadlocks - even the
constructor call to the proxy. So I guess this is a possible bug or me
missing something obvious.
Words can't describe as much as code, so I'm throwing in a couple of code
snippets for the above two solutions.
The CallWebServiceGui code (a simple form with a button that invokes a web
service and a thread that is listening for standard input in IPC means):
public partial class CallWebServiceGui : Form
{
public CallWebServiceGui ()
{
InitializeComponent();
}
private void CallWebServiceGui_Load(object sender, EventArgs e)
{
new Thread( new ThreadStart( WaitForInput ) ).Start();
// Give thread time to start...
Thread.Sleep( 200 );
}
private void WaitForInput ()
{
Stream stdin = Console.OpenStandardInput();
// Wait for input...
int rv = stdin.ReadByte();
}
private void buttonHelloWorld_Click(object sender, EventArgs e)
{
// !!! Deadlock HERE !!!
HelloWorld.Service hw = new
TestWebService.HelloWorld.Service();
// !!! Never gets here !!!
string str = hw.HelloWorld();
MessageBox.Show( str );
}
}
The web service above is the default HelloWorld web service generated by
VS2005 when creating a WS project. Not a single line of code was changed.
Here is also a code snippet for the starting application - the WsGuiStarter.
public partial class WsGuiStarter : Form
{
public WsGuiStarter()
{
InitializeComponent();
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
if ( openFileDialog.ShowDialog() == DialogResult.OK )
textBoxPath.Text = openFileDialog.FileName;
}
Process process = new Process();
private void buttonRun_Click(object sender, EventArgs e)
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.FileName = textBoxPath.Text;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
}
}
If the CallWebServiceGui doesn't have it's standard input redirected it
works perfectly. If it does, it deadlocks. Just for clarity's sake let me say
that the web service URL is correct, the HelloWeb service is running, both
project work, the web service call is not being the reason to block (I know I
have to wait a bit to get the response from a WS). Therefore I'm pointing out
again that the above sample works flawlessly if it doesn't have the standard
input redirected. If it does, it deadlocks.
I'd really like to know if this is a bug or not. Standard input seems like
an elegant and simple way of IPC (communicating between processes) and I
would really like to use it over any other method - for simplicity's sake and
not for me not knowing any other IPC technologies.
So is it a bug or me doing something wrong? I can also share a .zip
containing the whole solution to test the above stuff through.
Thanks!
Miha