Web service Asynchronous call fails

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

    Default Web service Asynchronous call fails

    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


    anonymus Guest

  2. Similar Questions and Discussions

    1. Asynchronous Web Service Call
      Karl, If the webservice is out of process (whether it be on another machine or just out of process), then it will be executed using a thread from...
    2. asynchronous call to web service from a web page
      My web service is to update a database. When user clicks on a button on a web page, it calls web service to update database. With hundred...
    3. how to make asynchronous call to web service when its OneWay property is set to true.
      I have web service with the following signature public void Update(XmlElement objElement) { // //call another C# library that update the...
    4. Asynchronous Web Service Call Fails
      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...
    5. Web servive asynchronous call fails
      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...
  3. #2

    Default Re: Web service Asynchronous call fails

    The issue lies with your calling of the async webmethod, not the web service
    itself. To the web service, your proxy's call is treated as synchronous
    from its prospective. It doesn't know how you invoked the call. Why don't
    you post your asynchronous call in an example format and I'm sure we can
    help you. Are you calling the async method with waitHandles, callback
    functions...?

    EX:

    IAsync example using delegates -- for example SomeMethod returns int

    private void invokeMethod(string args){

    <proxy_class_instance>.BeginSomeMethod(new
    AsyncCallback(SomeMethod_Callback),null)

    }

    private void count_Complete(IAsyncResult ir)

    {

    int i = <proxy_class_instance>.EndSomeMethod(ir);

    Debug.WriteLine(i.ToString());

    }

    IAsync example using IAsyncResult in synchronous fashion

    private void invokeMethod(string args){

    IAsyncResult ir = <proxy_class_instance>.BeginSomeMethod(null,null )
    int i = <proxy_class_instance>.EndSomeMethod(ir);
    Debug.WriteLine(i.ToString());


    }

    There are other ways to call it as well (using waithandles,
    manualresetevents, etc..)but my guess would be to try one of these options.
    If you still have the same problem, just post the code.

    Alex

    "anonymus" <anonymous@discussions.microsoft.com> wrote in message
    news:6BBEECA6-4746-4E5C-9B34-6C6392415FF6@microsoft.com...
    > 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
    >
    >

    Trebek Guest

  4. #3

    Default Re: Web service Asynchronous call fails

    Hi Trebek
    Please find the sample code as below.

    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;
    }
    }

    I tried using Thread.Sleep() in 'While' loopin client code .As well as i tried to catch the error exception by placing a try/ catch to my callback method in client code but none of them helped me either



    nirk Guest

  5. #4

    Default Re: Web service Asynchronous call fails

    Nirk,

    Due to async calls coming back on different thread pool threads, try taking
    the webservice call out of the 'Main' method and instead add it to some
    other method and see if the result is the same. Using your code, I had no
    trouble calling the WS method from another method of my instance class.

    HTH,
    Alex

    "nirk" <anonymous@discussions.microsoft.com> wrote in message
    news:0139BFF5-40C8-415A-B9B6-73A8631073AB@microsoft.com...
    > Hi Trebek
    > Please find the sample code as below.
    >
    > 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;
    > }
    > }
    >
    > I tried using Thread.Sleep() in 'While' loopin client code .As well as i
    tried to catch the error exception by placing a try/ catch to my callback
    method in client code but none of them helped me either
    >
    >
    >

    Trebek Guest

  6. #5

    Default Re: Web service Asynchronous call fails

    Hi Trebe
    Pls post yur client code i want to have a look to i

    Thanks in advanc
    Nirk
    nirk Guest

  7. #6

    Default Web service Asynchronous call fails

    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.The client is cretae dusing VS.NET envoirment as an console application.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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139