使用SilverLight构建插件式应用程序(七)

留言板插件的添加:

   

 这是一个添加留言的部分:代码比较简单:

  //留言对象
            NotesInfo ni = new NotesInfo();
            ni.UserName = UserName;
            ni.Title = this.txtTitle.Text;
            ni.Content = this.txtContent.Text;
            //服务路径
            Uri uri = System.Windows.Browser.HtmlPage.Document.DocumentUri;
            string host = uri.AbsoluteUri;
            host = host.Substring(0, host.Length - uri.LocalPath.Length);
            string servicePath = "/Services/WSNotes.svc";
            string serviceUri = host + servicePath;
            //构建服务,开始保存
            WSNotesClient ws = new WSNotesClient(new System.ServiceModel.BasicHttpBinding(), new System.ServiceModel.EndpointAddress(serviceUri));
            ws.InsertNotesCompleted += new EventHandler<InsertNotesCompletedEventArgs>(ws_InsertNotesCompleted);

            ws.InsertNotesAsync(ni);

保存完成之后,通知显示界面,重新刷新数据

  void ws_InsertNotesCompleted(object sender, InsertNotesCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                if (e.Result)
                {
                    if (OnSaveed != null)
                    {
                        OnSaveed(this, true);
                    }
                }
            }

        }

 这样,数据就可以立即显示当前用户输入的数据,同时避免用户多次提交相同数据的问题。

下一步是做一个即时的聊天程序,然后是做一个国际象棋的在线对战平台,欢迎对sl有兴趣的朋友加入。

预览:www.cuface.cn

原文地址:https://www.cnblogs.com/songsgroup/p/1310393.html