Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Web servive asynchronous call fails

Reply
Thread Tools

Web servive asynchronous call fails

 
 
nirk
Guest
Posts: n/a
 
      01-23-2004

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
 
Reply With Quote
 
 
 
 
Jan Tielens
Guest
Posts: n/a
 
      01-23-2004
Ok, can you post some code how you implemented your async. call?

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

--
Greetz

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


"nirk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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



 
Reply With Quote
 
 
 
 
nirk
Guest
Posts: n/a
 
      01-23-2004
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;
}
}
 
Reply With Quote
 
nirk
Guest
Posts: n/a
 
      01-23-2004
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


 
Reply With Quote
 
Sami Vaaraniemi
Guest
Posts: n/a
 
      01-23-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
> }
> }



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a Web Servive send it's status to a client? Ethan Strauss ASP .Net Web Services 6 02-11-2007 02:22 PM
Submitting a web form to a web server from a running windows servive. Muhammad Saifullah via .NET 247 ASP .Net 1 06-01-2005 09:11 AM
Web service Asynchronous call fails nirk ASP .Net Web Services 0 02-04-2004 04:16 AM
Web service Asynchronous call fails anonymus ASP .Net Web Services 4 01-29-2004 03:31 AM
Asynchronous Web Service Call Fails nirk ASP .Net Web Services 0 01-27-2004 03:41 AM



Advertisments