473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

WebForm + Callback

HI, I'm learning about WCF.
I've written a simple service and I'm trying to write a web-form
client.
On a simple console client that's all right. I've got the problem with
the asynchronous callback in the client.
When I click Button1 the client send request to the service and I
return the callback correctly:
variable 'res' contains the correct return value but not 'Label2'
I'm sure I forgot something, can anybody help me?
PS: sorry for my english

Here's the code for defult.aspx.vb
Imports System.ServiceModel

Partial Class _Default
Inherits System.Web.UI.Page

Private Sub Add_Callback(ByVal ar As IAsyncResult)
Dim Client As CalculatorClient = DirectCast(ar.AsyncState,
CalculatorClient)
Dim res As String = Client.EndAdd(ar)
Label2.text = res '<---Label2.text could non be
refresh!!!!!!!!!!!
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Label1.Text = Client.Add(CDbl(Text1.Text))
Client.Close()
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Dim ar As IAsyncResult = Client.BeginAdd(CDbl(Text2.Text), New
AsyncCallback(AddressOf Add_Callback), Client)
End Sub

End Class

Thank you

Jul 13 '07 #1
2 1929
in prerender you need to add a wait for the async routine to complete,
so that its effects can be seen in the returned html. as you have it
now, the html is returned and the browser has rendered the page before
the async has completed. updating the servers version of the lbel is
meanless. remember each request (button click) creates a new class
instance to process the request.

-- bruce (sqlwork.com)


sandrofurlan wrote:
HI, I'm learning about WCF.
I've written a simple service and I'm trying to write a web-form
client.
On a simple console client that's all right. I've got the problem with
the asynchronous callback in the client.
When I click Button1 the client send request to the service and I
return the callback correctly:
variable 'res' contains the correct return value but not 'Label2'
I'm sure I forgot something, can anybody help me?
PS: sorry for my english

Here's the code for defult.aspx.vb
Imports System.ServiceModel

Partial Class _Default
Inherits System.Web.UI.Page

Private Sub Add_Callback(ByVal ar As IAsyncResult)
Dim Client As CalculatorClient = DirectCast(ar.AsyncState,
CalculatorClient)
Dim res As String = Client.EndAdd(ar)
Label2.text = res '<---Label2.text could non be
refresh!!!!!!!!!!!
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Label1.Text = Client.Add(CDbl(Text1.Text))
Client.Close()
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Dim ar As IAsyncResult = Client.BeginAdd(CDbl(Text2.Text), New
AsyncCallback(AddressOf Add_Callback), Client)
End Sub

End Class

Thank you
Jul 13 '07 #2
On 13 Lug, 17:33, bruce barker <nos...@nospam.comwrote:
in prerender you need to add a wait for the async routine to complete,
so that its effects can be seen in the returned html. as you have it
now, the html is returned and the browser has rendered the page before
the async has completed. updating the servers version of the lbel is
meanless. remember each request (button click) creates a new class
instance to process the request.

-- bruce (sqlwork.com)

sandrofurlanwrote:
HI, I'm learning about WCF.
I've written a simple service and I'm trying to write a web-form
client.
On a simple console client that's all right. I've got the problem with
the asynchronous callback in the client.
When I click Button1 the client send request to the service and I
return the callback correctly:
variable 'res' contains the correct return value but not 'Label2'
I'm sure I forgot something, can anybody help me?
PS: sorry for my english
Here's the code for defult.aspx.vb
Imports System.ServiceModel
Partial Class _Default
Inherits System.Web.UI.Page
Private Sub Add_Callback(ByVal ar As IAsyncResult)
Dim Client As CalculatorClient = DirectCast(ar.AsyncState,
CalculatorClient)
Dim res As String = Client.EndAdd(ar)
Label2.text = res '<---Label2.text could non be
refresh!!!!!!!!!!!
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Label1.Text = Client.Add(CDbl(Text1.Text))
Client.Close()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Dim ar As IAsyncResult = Client.BeginAdd(CDbl(Text2.Text), New
AsyncCallback(AddressOf Add_Callback), Client)
End Sub
End Class
Thank you
It works fine! Thanks Bruce,
I post the code
bye

Imports System.ServiceModel
Imports System.Threading

Partial Class _Default
Inherits System.Web.UI.Page

Private WaitForResponse As New ManualResetEvent(False)

' callback method
Private Sub Add_Callback(ByVal ar As IAsyncResult)
' create a new instance of client
Dim Client As CalculatorClient = DirectCast(ar.AsyncState,
CalculatorClient)
' get the result operation
Dim res As String = Client.EndAdd(ar)
' store it
Label2.Text = res
' signal event to unlock page
WaitForResponse.Set()
End Sub

' sync method: when the service is down it doesn't work!!!!!
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim Client As New CalculatorClient
Label1.Text = Client.Add(CDbl(Text1.Text))
Client.Close()
End Sub

' async method
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
'create a new instance of client
Dim Client As New CalculatorClient
'call aync method
Dim ar As IAsyncResult = Client.BeginAdd(CDbl(Text2.Text), New
AsyncCallback(AddressOf Add_Callback), Client)
End Sub

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.PreRender
If IsPostBack Then
Try
'wait for the async end method
If Not
WaitForResponse.WaitOne(TimeSpan.FromMilliseconds( 1000), True) Then
Throw New TimeoutException()
Catch ex As TimeoutException
Response.Write(ex.Message)
End Try
End If
End Sub
End Class

Jul 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: scott ocamb | last post by:
hello I have implemented a solution using async methods. There is one async method that can be invoked multiple times, ie there are multiple async "threads" running at a time. When these...
0
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion is as follows **************************************** The Original Fucntion in the dll...
4
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
2
by: MR | last post by:
help! I have an unmanaged DLL that I do not have the source code, so i can't recompile or make changes. the DLL requires a callback function. I would like to implement the callback method in a...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.