一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

在 .NET 中使用 WEB SERVICE 的CallBacks机制 (5)

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

3. Web Form
对于WebService”A”我们使用的浏览器作为客户端。
 每个 Web Methods有自己的按钮触发事件,在栈(Stack)中来保存Session类的状态。
 页面的更新基于下面的机制:事件处理程序把数据压到Session栈,在Page_Load时提取出来并且插入到ListBox control中。另一个议题是以异步方式调用DoSomeWorkA方法,它可以产生和处理callback,这就是我们为什么能送另一个请求给WebService”A”的原因。注意每项工作都被它的验证票据ID所识别。
namespace WebFormCallbackWS
{
public class WebForm1 : System.Web.UI.Page
{
// ...
protected ServiceA sa = new ServiceA();
public WebForm1()
{
Page.Init += new System.EventHandler(Page_Init);
}

private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack == false)
{
//initialize controls, one time!
if(Session["Status"] == null)
Session["Status"] = Stack.Synchronized(new Stack());
}
else
{
Stack stack = Session["Status"] as Stack;
while(stack.Count > 0)
ListBoxCallbackStatus.Items.Add(stack.Pop().ToString());

int numberOfItems = ListBoxCallbackStatus.Items.Count;
if(numberOfItems > 13)
ListBoxCallbackStatus.SelectedIndex = numberOfItems - 13;
}
}
private void Page_Init(object sender, EventArgs e)
{
// ...
}

#region Web Form Designer generated code

热门栏目