Deadlock when constructing a Web Service!!!

C

Crnjan

Hello!

I recently found a strange phenomenon. I am using a simple Windows
Application based application written in C# (lets name it
TestWebServiceStrangePhenomenom). The TestWebServiceStrangePhenomenom
application is started from another application which also redirects
standard input from TestWebServiceStrangePhenomenom. The
TestWebServiceStrangePhenomenom creates a new thread and within it,
waits for input from app that started it (the redirected standard input
stream is used for IPC). And now comes the strange part: if I add a new
button to windows form and in the click action call some web service,
the web service deadlocks!!!

I wrote a simple demo application to demonstrate the problem.

The TestWebServiceStrangePhenomenom code:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_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();
string str = hw.HelloWorld();

MessageBox.Show( str );
}
}


For the web service I used the default ASP.Net Web Service sample
(HelloWorld) that is automaticaly generated within VS2005.

And also the code for starting the TestWebServiceStrangePhenomenom
(another project):

public partial class mainForm : Form
{
public mainForm()
{
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 TestWebServiceStrangePhenomenom has not got the input stream
redirected, than the web service will work!
 
P

Peter Ritchie [C# MVP]

What do you mean by "deadlock". There's nothing in click handler that
"deadlocks" in the normal mutli-threaded use of the work.

Do you simply mean your application stops responding to user input while
waiting for the web service operation to execute?
 
C

Crnjan

No. The executing stops within web service's constructor. The web
service (Hello World) is running on local machine so their in NO way
that web service could deadlock. The execution simply stops. If the
same web service is invoked from other application the web service
works without problems. The web service also works if it is invoked
from same application if the standard input is not redirected as stated
above.

So to repeat the scenario:

If the TestWebServiceStrangePhenomenom application is simply run (for
example from VS2005 environment) than there is NO problem executing web
service.

If the TestWebServiceStrangePhenomenom application is run from other
application that redirects TestWebServiceStrangePhenomenom's standard
input, than web service doesn't work. Its execution stops when
executing constructor:

HelloWorld.Service hw = new TestWebService.HelloWorld.Service();


Hope I was clear enough,
crnjan


Peter je napisal:
 
C

Crnjan

For the sake of clearety I have to state that I waited for 1 (one!)
whole hour to continue executing without any success. Because this is a
very simple web service returning only a simple string and running on
same machine I think that is more than enought ïŠ.

I can also provide VS2005 projects if someone is interested in trying
the strange phenomena for himself, just send me an e-mail and I wil
send the projects to you.

Hope for a solution soon,
Crnjan

Crnjan je napisal:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top