Deadlock when constructing a Web Service!!!

Discussion in 'ASP .Net Web Services' started by Crnjan, Sep 11, 2006.

  1. Crnjan

    Crnjan Guest

    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!
     
    Crnjan, Sep 11, 2006
    #1
    1. Advertisements

  2. 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?

    --
    Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    http://www.peterRitchie.com/blog/
    Microsoft MVP, Visual Developer - Visual C#


    "Crnjan" wrote:

    > 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!
    >
    >
     
    Peter Ritchie [C# MVP], Sep 12, 2006
    #2
    1. Advertisements

  3. Crnjan

    Crnjan Guest

    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:
    > 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?
    >
    > --
    > Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    > http://www.peterRitchie.com/blog/
    > Microsoft MVP, Visual Developer - Visual C#
    >
    >
    > "Crnjan" wrote:
    >
    > > 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!
    > >
    > >
     
    Crnjan, Sep 12, 2006
    #3
  4. Crnjan

    Crnjan Guest

    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:
    > 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:
    > > 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?
    > >
    > > --
    > > Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
    > > http://www.peterRitchie.com/blog/
    > > Microsoft MVP, Visual Developer - Visual C#
    > >
    > >
    > > "Crnjan" wrote:
    > >
    > > > 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!
    > > >
    > > >
     
    Crnjan, Sep 12, 2006
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hocho888
    Replies:
    1
    Views:
    881
  2. Michael Averstegge
    Replies:
    0
    Views:
    4,563
    Michael Averstegge
    Jan 10, 2006
  3. Not Me
    Replies:
    1
    Views:
    3,476
    Not Me
    Jun 5, 2007
  4. Isaias Formacio Serna

    Web Service that calls an external Web Service

    Isaias Formacio Serna, Jan 28, 2004, in forum: ASP .Net Security
    Replies:
    5
    Views:
    469
  5. Replies:
    1
    Views:
    413
    Joe Kaplan \(MVP - ADSI\)
    Jun 14, 2006
  6. dgleeson422111

    Consuming local web service - ok, remote web service -problem?

    dgleeson422111, Jan 26, 2010, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    1,093
    dgleeson422111
    Jan 26, 2010
  7. JC

    Calling a web service from a web service

    JC, Aug 16, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    262
    Tom Vande Stouwe MCSD.net
    Aug 20, 2003
  8. Leo Violette
    Replies:
    0
    Views:
    1,317
    Leo Violette
    Apr 17, 2009
Loading...