Web servive asynchronous call fails

Discussion in 'ASP .Net Web Services' started by nirk, Jan 23, 2004.

  1. nirk

    nirk Guest

    Hi
    I created a webservice with a simple we method to increment a number passed from the client(a console app) .
    Then i call this web service method asynchronus mode from the client.
    I create a callback function and call EndXXX(XXX denotes the function name) in the callback function.
    But the function call never ends. means the web service is not working in async mode
    I have added the web refernce properly because i was able to succesfully call the same function in synchronous mode

    Where am i going wrong

    Thanks in advance
    Nirk
     
    nirk, Jan 23, 2004
    #1
    1. Advertising

  2. nirk

    Jan Tielens Guest

    Ok, can you post some code how you implemented your async. call?

    Maybe you can read following article:
    http://weblogs.asp.net/rosherove/archive/2003/10/26/33545.aspx

    --
    Greetz

    Jan Tielens
    ________________________________
    Read my weblog: http://weblogs.asp.net/jan


    "nirk" <> wrote in message
    news:...
    >
    > Hi
    > I created a webservice with a simple we method to increment a number

    passed from the client(a console app) .
    > Then i call this web service method asynchronus mode from the client.
    > I create a callback function and call EndXXX(XXX denotes the function

    name) in the callback function.
    > But the function call never ends. means the web service is not working in

    async mode
    > I have added the web refernce properly because i was able to succesfully

    call the same function in synchronous mode
    >
    > Where am i going wrong
    >
    > Thanks in advance
    > Nirk
     
    Jan Tielens, Jan 23, 2004
    #2
    1. Advertising

  3. nirk

    nirk Guest

    Hi Jan
    The web service code is one of yur articles in the code project.Client i created in VS.net envoirment.

    CLIENT CODE
    class Class1
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static bool bEnd= false;


    public static void PrimeCallback(IAsyncResult arResult)
    {
    // Obtains the last parameter of the delegate call.

    Console.WriteLine ("Inside PrimeCallback");
    // get the "this" pointer that was passed...
    WSPrime wsp=(WSPrime)arResult.AsyncState;

    // call "EndPrime" and get the result..
    int iCount=wsp.EndPrime(arResult);

    /// show the result of the webservice call..
    Console.WriteLine("Async. WebService call found {0} primes.", iCount);

    // set flag so that application can terminate...
    bEnd=true;

    }
    [STAThread]
    static void Main(string[] args)
    {

    try
    {
    int intTemp;
    IAsyncResult ar;
    Console.WriteLine("Calling WebService Asynchronously...\n");
    AsyncCallback ascb = new AsyncCallback (Class1.PrimeCallback);
    //for (int i =2;i<=10;i++)
    {
    WSPrime wsp = new WSPrime();
    //intTemp = wsp.Prime (10);
    wsp.BeginPrime(10,ascb,wsp);

    }


    Console.WriteLine ("waiting for WebService");
    while(bEnd == false);
    Console.WriteLine ("Over" );
    Console.ReadLine ();
    }

    //
    // TODO: Add code to start application here
    //
    catch(System.Exception exception)
    {
    Console.WriteLine (exception.Message);
    }
    }


    };

    WEBSERVICE CODE
    using System.Web.Services;

    public class WSPrime : WebService
    {
    // This method returns the number of prime number lying between
    // 2 and num.
    [WebMethod]
    public int Prime(int num)
    {
    int iCount=0;
    for(int i=2;i<num;i++)
    {
    bool bPrime=true;
    for(int j=2;j<i;j++)
    {
    // is this number prime ?
    if (i%j==0)
    {
    // nope.. it isn't...
    bPrime=false;
    break;
    }
    }

    if (bPrime==true)
    iCount++;
    }

    // return the count..
    return iCount;
    }
    }
     
    nirk, Jan 23, 2004
    #3
  4. nirk

    nirk Guest

    H
    The solution did not help either
    If i compile the webservice client(Class1.cs), by referencing the webservice proxy assembly, as given belo
    csc /r:wsprime.dll Class1.c
    where wsprime.dll is same folder in which Class1.cs is there i am easily able to get the asynchronous call but from the actual exe(the console application) i fail to do

    Pls advice
     
    nirk, Jan 23, 2004
    #4
  5. I see a couple of problems in the code.

    You have a busy loop in the main thread: while(bEnd == false); This probably
    does not prevent the asynchronous call from completing because the thread
    pool threads run by default with the same priority as your main thread.
    Nevertheless a busy loop like this is considered bad. Add a call to
    Thread.Sleep to the loop.

    A possible problem that could make your program hang is that there is an
    exception when you call the EndPrime method. Since you don't handle the
    exception and it occurs in the threadpool thread, it just disappears
    silently. To find out what the problem is, add a try/catch to your
    asynchronous callback:

    public static void PrimeCallback(IAsyncResult arResult)
    {
    try
    {
    // Obtains the last parameter of the delegate call.

    Console.WriteLine ("Inside PrimeCallback");
    // get the "this" pointer that was passed...
    WSPrime wsp=(WSPrime)arResult.AsyncState;

    // call "EndPrime" and get the result..
    int iCount=wsp.EndPrime(arResult);

    /// show the result of the webservice call..
    Console.WriteLine("Async. WebService call found {0} primes.", iCount);

    // set flag so that application can terminate...
    bEnd=true;
    }
    catch (Exception ex)
    {
    Console.WriteLine("Web Service call failed: " + ex.ToString());
    bEnd = true;
    }
    }

    If there is an exception, at least this helps you see what the problem is.
    Sami

    "nirk" <> wrote in message
    news:...
    > Hi Jan
    > The web service code is one of yur articles in the code project.Client i

    created in VS.net envoirment.
    >
    > CLIENT CODE
    > class Class1
    > {
    > /// <summary>
    > /// The main entry point for the application.
    > /// </summary>
    > private static bool bEnd= false;
    >
    >
    > public static void PrimeCallback(IAsyncResult arResult)
    > {
    > // Obtains the last parameter of the delegate call.
    >
    > Console.WriteLine ("Inside PrimeCallback");
    > // get the "this" pointer that was passed...
    > WSPrime wsp=(WSPrime)arResult.AsyncState;
    >
    > // call "EndPrime" and get the result..
    > int iCount=wsp.EndPrime(arResult);
    >
    > /// show the result of the webservice call..
    > Console.WriteLine("Async. WebService call found {0} primes.", iCount);
    >
    > // set flag so that application can terminate...
    > bEnd=true;
    >
    > }
    > [STAThread]
    > static void Main(string[] args)
    > {
    >
    > try
    > {
    > int intTemp;
    > IAsyncResult ar;
    > Console.WriteLine("Calling WebService Asynchronously...\n");
    > AsyncCallback ascb = new AsyncCallback (Class1.PrimeCallback);
    > //for (int i =2;i<=10;i++)
    > {
    > WSPrime wsp = new WSPrime();
    > //intTemp = wsp.Prime (10);
    > wsp.BeginPrime(10,ascb,wsp);
    >
    > }
    >
    >
    > Console.WriteLine ("waiting for WebService");
    > while(bEnd == false);
    > Console.WriteLine ("Over" );
    > Console.ReadLine ();
    > }
    >
    > //
    > // TODO: Add code to start application here
    > //
    > catch(System.Exception exception)
    > {
    > Console.WriteLine (exception.Message);
    > }
    > }
    >
    >
    > };
    >
    > WEBSERVICE CODE
    > using System.Web.Services;
    >
    > public class WSPrime : WebService
    > {
    > // This method returns the number of prime number lying between
    > // 2 and num.
    > [WebMethod]
    > public int Prime(int num)
    > {
    > int iCount=0;
    > for(int i=2;i<num;i++)
    > {
    > bool bPrime=true;
    > for(int j=2;j<i;j++)
    > {
    > // is this number prime ?
    > if (i%j==0)
    > {
    > // nope.. it isn't...
    > bPrime=false;
    > break;
    > }
    > }
    >
    > if (bPrime==true)
    > iCount++;
    > }
    >
    > // return the count..
    > return iCount;
    > }
    > }
     
    Sami Vaaraniemi, Jan 23, 2004
    #5
    1. Advertising

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. nirk

    Asynchronous Web Service Call Fails

    nirk, Jan 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    111
  2. anonymus

    Web service Asynchronous call fails

    anonymus, Jan 27, 2004, in forum: ASP .Net Web Services
    Replies:
    4
    Views:
    147
  3. nirk

    Web service Asynchronous call fails

    nirk, Feb 4, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    124
  4. mimi

    asynchronous call to web service from a web page

    mimi, Jul 22, 2004, in forum: ASP .Net Web Services
    Replies:
    5
    Views:
    160
  5. Ethan Strauss

    Can a Web Servive send it's status to a client?

    Ethan Strauss, Jan 29, 2007, in forum: ASP .Net Web Services
    Replies:
    6
    Views:
    169
    Alvin Bruney [MVP]
    Feb 11, 2007
Loading...

Share This Page