Tutorials to .com

Tutorials to .com » Dotnet » Foundation » asp.net2.0 the asynchronous call WebService (asynchronous pages)

asp.net2.0 the asynchronous call WebService (asynchronous pages)

Print View , by: iSee ,Total views: 9 ,Word Count: 473 ,Date: Mon, 24 Aug 2009 Time: 4:00 PM

As asp2.0 provides support for asynchronous pages so that the performance of an asynchronous call to WebService to have a real improvement.
Use asynchronous pages, we must first set the Async = "true", asynchronous page is between events in the Prerender and PrerenderComplete joined Begin, end the asynchronous method implementation, Begin and End methods belong to different threads.
Implementation of WS asynchronous page in two ways:
1, use the method to wait for asynchronous generic class encapsulates the WS
/**//// <summary>
/ / / Method to use to wait for asynchronous
/ / / </ Summary>
/ / / <param Name="name"> </ param>
/ / / <returns> </ Returns>
private Account account;
private string username;
public Account Account
(
get (return account;)
set (account = value;)
)
public string Username
(
get (return username;)
set (username = value;)
)
public IAsyncResult BeginAsyncGetAccount (object sender, EventArgs e, AsyncCallback cb, object state)
(

return vb.BeginGetAccountbyName (username, cb, state);
)
public void EndAsyncGetAccount (IAsyncResult ar)
(
account = vb.EndGetAccountbyName (ar);
)

/**//// <summary>
/ / / Use event-driven asynchronous
/ / / </ Summary>
/ / / <param Name="username"> </ param>
public void GetAccountCompleted (Object source, VB.GetAccountbyNameCompletedEventArgs e)
(
account = e.Result;
)
public void AsGetAccount (string username)
(
vb.GetAccountbyNameCompleted + = new GetAccountbyNameCompletedEventHandler (GetAccountCompleted);
vb.GetAccountbyNameAsync (username)

Call the method)
protected void Page_Load (object sender, EventArgs e)
(
this.PreRenderComplete + = new EventHandler (Page_PreRenderComplete);
b.Username = "dinghao";

AddOnPreRenderCompleteAsync (b.BeginAsyncGetAccount, b.EndAsyncGetAccount);
)
protected void Page_PreRenderComplete (object sender, EventArgs e)
(
/ / Asynchronous call to
VB.Account a = b.Account;
AccountIf ai = new AccountIf (a);
ais [0] = ai;
GridView1.DataSource = ais;
GridView1.DataBind ();
) Because the two delegate AddOnPreRenderCompleteAsync are Void type, so in general-purpose class to join the attributes to return values, such as: Account for the main theme of ways to use, while there is no asynchronous delegate method parameter information, to join the properties of parameters such as the : Username
2, event-driven asynchronous (2.0 new)
Call the method:
protected void Page_Load (object sender, EventArgs e)
(
this.PreRenderComplete + = new EventHandler (Page_PreRenderComplete);
b.AsGetAccount ( "dinghao");

)
protected void Page_PreRenderComplete (object sender, EventArgs e)
(
/ / Asynchronous call to
VB.Account a = b.Account;
AccountIf ai = new AccountIf (a);
ais [0] = ai;
GridView1.DataSource = ais;
GridView1.DataBind ();
) This method is called, using a * Completed event, * Async completion trigger, this approach eliminates the need for calling Account, Username attributes, relatively simple to use up

http://bluewater.cnblogs.com/archive/2006/06/20/430758.html


.NET foundation Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.