加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebService异步调用(与委托有关)

发布时间:2020-12-17 02:38:15 所属栏目:安全 来源:网络整理
导读:using ?System; using ?System.Collections.Generic; using ?System.ComponentModel; using ?System.Data; using ?System.Drawing; using ?System.Linq; using ?System.Text; using ?System.Windows.Forms; namespace ?WindowsFormsApplication1 { ?????? pu
  1. using?System;
  2. using?System.Collections.Generic;
  3. using?System.ComponentModel;
  4. using?System.Data;
  5. using?System.Drawing;
  6. using?System.Linq;
  7. using?System.Text;
  8. using?System.Windows.Forms;
  9. namespace?WindowsFormsApplication1
  10. {
  11. ??????public?partial?class?Form1?:?Form
  12. ??????{
  13. ??????????public?Form1()
  14. ??????????{
  15. ??????????????InitializeComponent();
  16. ??????????}
  17. ??????????private?void?button1_Click(object?sender,?EventArgs?e)
  18. ??????????{
  19. ??????????????localhost.Service?t?=?new?WindowsFormsApplication1.localhost.Service();
  20. ??????????????MessageBox.Show(t.HelloWorld());
  21. ??????????????MessageBox.Show("Down!");
  22. ??????????}
  23. ??????????private?void?button2_Click(object?sender,?EventArgs?e)
  24. ??????????{
  25. ??????????????localhost.Service?t?=?new?WindowsFormsApplication1.localhost.Service();
  26. ??????????????t.HelloWorldCompleted?+=?new?WindowsFormsApplication1.localhost.HelloWorldCompletedEventHandler(t_HellowordCompleted);
  27. ??????????????t.HelloWorldAsync();
  28. ??????????????MessageBox.Show("Down!");
  29. ??????????}
  30. ??????????private?void?t_HellowordCompleted(object?sender,?localhost.HelloWorldCompletedEventArgs?e)
  31. ??????????{
  32. ??????????????MessageBox.Show(e.Result.ToString());
  33. ??????????}
  34. ??????????private?void?button3_Click(object?sender,?EventArgs?e)
  35. ??????????{
  36. ??????????????MessageBox.Show((new?localhost.Service()).GetTime());
  37. ??????????}
  38. ??????}
  39. }
  40. ---------------------webService----------------------------
  41. using?System;
  42. using?System.Linq;
  43. using?System.Web;
  44. using?System.Web.Services;
  45. using?System.Web.Services.Protocols;
  46. using?System.Xml.Linq;
  47. using?System.Threading;
  48. [WebService(Namespace?=?"http://tempuri.org/")]
  49. [WebServiceBinding(ConformsTo?=?WsiProfiles.BasicProfile1_1)]
  50. //?To?allow?this?Web?Service?to?be?called?from?script,?using?ASP.NET?AJAX,?uncomment?the?following?line.?
  51. //?[System.Web.Script.Services.ScriptService]
  52. public?class?Service?:?System.Web.Services.WebService
  53. {
  54. ?????public?Service?()?{
  55. ?????????//Uncomment?the?following?line?if?using?designed?components?
  56. ?????????//InitializeComponent();?
  57. ?????}
  58. ?????[WebMethod]
  59. ?????public?string?HelloWorld()?{
  60. ?????????Thread.Sleep(3000);
  61. ?????????return?"Hello?World";
  62. ?????}
  63. ????////缓存10秒
  64. ?????[WebMethod(false,System.EnterpriseServices.TransactionOption.NotSupported,10)]
  65. ?????public?string?GetTime()
  66. ?????{
  67. ?????????return?DateTime.Now.ToString();
  68. ?????}
  69. ????
  70. }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读