ASP.Net with Asynchronous Web Service calls

G

Guest

Hi
I have asked a similar question on the web services discussion group, but the question is a bit more related to ASP.Net. Basically I have a ASP.Net application that calls a web service asynchronously. This is fine. My problem is that when I make a call to the web service asynchronously when I get the return which is passed into a static method I cannot reference any Web Contorls to paste the return values into from within the static method.

I have been advised to create a static field and add the value retuned to the static methos to the static field which should be referenceable from all methods. Again fine.

However my question is how do I then tell the cntrol that will display my returned value to pick it up?

A typical sequence would b

1. Client makes async call. Passes in static methos name to send the results to on completion
2. browser can do wor
3. static method picks up result,
4. needs to tell asp.net to now pick up the result and show it

point 4 is my problem

Any help appreciated
 
R

Rick Spiewak

You need to have your static method be part of a class, and create an event
in the class. In your ASP.NET routine, attach a delegate (handler) to the
event, and raise it when you have the results.

Trotsky said:
Hi,
I have asked a similar question on the web services discussion group,
but the question is a bit more related to ASP.Net. Basically I have a
ASP.Net application that calls a web service asynchronously. This is fine.
My problem is that when I make a call to the web service asynchronously when
I get the return which is passed into a static method I cannot reference any
Web Contorls to paste the return values into from within the static method.
I have been advised to create a static field and add the value retuned to
the static methos to the static field which should be referenceable from all
methods. Again fine.
 
R

Rick Spiewak

Not for this specific case, but you might want to prowl around for general
information about delegates and events.
 
G

Guest

Thanks again. I had a go at this. However I have came across another issue. My app now does the followin

1. Creates a class ( AsynCall.cs ) that takes care of the asynchronous web services call, and raising of events when the result is returned from the web service
2. passes a reference from the .aspx.cs class ( this ) to the AsynCall object. This is because the .aspx.cs class will be listening for the reslt when it is available from the Asyn web services call
3. The AsynCall class defines an event that is raised when the asynchronous call returns. The .aspx.cs class has a method that matches the method definition defined by a delegate in AsyncCall.cs, and has registered its method with the handler
4. The aync result is returned and the appropriate event is raised, I can write to debug to check I am in the correct aspx.cs class and the correct result has been returned from the web service call
5. When I try to then write the result to a label on the form nothing appears.

point 5 is my problem

again any help greatly appreciated
 
R

Rick Spiewak

The page isn't being reloaded just because the event occurs. You might have
to force this - try saving the result from the web service in session state,
(or adding it to your page's URL as a query string) and then do a
server.transfer back to the same page, pick up the value and put it into
your control. (I haven't tried this <g>)

Trotsky said:
Thanks again. I had a go at this. However I have came across another
issue. My app now does the following
1. Creates a class ( AsynCall.cs ) that takes care of the asynchronous web
services call, and raising of events when the result is returned from the
web service.
2. passes a reference from the .aspx.cs class ( this ) to the AsynCall
object. This is because the .aspx.cs class will be listening for the reslt
when it is available from the Asyn web services call.
3. The AsynCall class defines an event that is raised when the
asynchronous call returns. The .aspx.cs class has a method that matches the
method definition defined by a delegate in AsyncCall.cs, and has registered
its method with the handler.
4. The aync result is returned and the appropriate event is raised, I can
write to debug to check I am in the correct aspx.cs class and the correct
result has been returned from the web service call.
 
G

Guest

I tried your suggestion ( and also a simple redirect to a new page ) from my method in the original aspx.cs class that matches the delegates required signature, but nothing happened ( on the Page, it still logs to the debug window that it is in the correct method )
 
G

Guest

I went through the stack trace and for a redirect it ( the aspx page ) throws an exception stating

"Response is not available in this context

For the Server.Transfer I get "Error executing child request for". MSDN recommends redirect.

http://support.microsoft.com/default.aspx?scid=kb;en-us;32043

Regardless both fail
The annoying this is when I look in the locals window I can see the result returned from the web service is assigned to the label control on the form. It just isn't reflected in the browser window.
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top