<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

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

      [摘要]3. Web Form對于WebService”A”我們使用的瀏覽器作為客戶端。 每個 Web Methods有自己的按鈕觸發事件,在棧(Stack)中來保存Session類的狀態。 頁面的更新基于...
      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
      private void InitializeComponent()
      {
      // ...
      }
      #endregion

      // Call the web service asynchronously
      private void ButtonDoSomeWorkA_Click(object sender, System.EventArgs e)
      {
      int count = Convert.ToInt32(TextBoxCount.Text);
      string ticket = TextBoxTicketId.Text;
      //
      AsyncCallback callback = new AsyncCallback(callbackDoSomeWorkA);
      IAsyncResult ar = sa.BeginDoSomeWorkA(count, ticket, callback, null);
      ListBoxCallbackStatus.Items.Add(string.Format("#{0} start ...",
      ticket));
      }
      // the call callback from the WebService
      private void callbackDoSomeWorkA(IAsyncResult ar)
      {
      string retval = sa.EndDoSomeWorkA(ar);
      Stack stack = Session["Status"] as Stack;
      stack.Push(retval);
      }
      // call the web service
      private void ButtonAbort_Click(object sender, System.EventArgs e)
      {
      Stack stack = Session["Status"] as Stack;
      stack.Push(sa.AbortWorkA(TextBoxTicketId.Text));

      }
      // Get the status from the web service
      private void ButtonRefresh_Click(object sender, System.EventArgs e)
      {
      Stack stack = Session["Status"] as Stack;
      stack.Push(sa.GetStatusWorkA(TextBoxTicketId.Text));
      }
      // clean-up the listbox
      private void ButtonClear_Click(object sender, System.EventArgs e)
      {
      ListBoxCallbackStatus.Items.Clear();
      }
      }
      }
      ok,我們現在開始做過測試。上述的照片顯示了Web 形式的用戶界面。 首先,確定你網絡聯機并且處于企業內部局域網絡。 在 DoSomeWork 按鈕上的單擊,然后請求狀態結果。Status 和Abort按鈕可以在容易時間點擊。 ListBox 控件將會顯示某個工作的當前狀態 (由驗證票據得到)
      結論:
      使用應用程序模型的 WEB SERVICE開創了分布式架構的一個新紀元。在企業化模型層次結構中使用.Net Framework動態的調用Web Methods是簡單的,很直接的。這篇文章說明它如何使用 C#語言來實現。 這種解決方案很好的解釋了相關的概念和設計時所設計的問題。如果真正投入到市場,還需要考慮許多因素,如安全設計,完整的 url 尋址,密碼,服務器代理等。


      日韩精品一区二区三区高清