189 8069 5689

C#WebServices升级程序

面介绍一种用C# Web Services升级程序。通过C# Web Services升级程序就象读写本机文件一样简单。所以我就直接给出代码。

兴化网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联自2013年创立以来到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

C# Web Services升级程序部分代码:

 
 
 
  1. using System;
  2. using System.Web;
  3. using System.Web.Services;
  4. using System.Web.Services.Protocols;
  5. using System.IO;
  6. [WebService(Namespace = "http://tempuri.org/")]
  7. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  8. public class Service : System.Web.Services.WebService
  9. {
  10. public Service()
  11. {
  12. //如果使用设计的组件,请取消注释以下行
  13. //InitializeComponent();
  14. }
  15. /// 
  16. /// 需要升级文件的服务器路径
  17. ///  summary>
  18. private const string UpdateServerPath ="d:\\Debug";
  19. [WebMethod(Description = "返回服务器上程序的版本号")]
  20. public string ServerVer()
  21. {
  22. return "4.0";
  23. }
  24. [WebMethod(Description = "返回需更新的文件")]
  25. public string[] NewFiles()
  26. {
  27. DirectoryInfo di = new DirectoryInfo(UpdateServerPath);
  28. FileInfo[] fi = di.GetFiles();
  29. int intFiles= fi.Length;
  30. string[] myNewFiles = new string[intFiles];
  31. int i = 0;
  32. foreach (FileInfo fiTemp in fi)
  33. {
  34. myNewFiles[i] = fiTemp.Name;
  35. System.Diagnostics.Debug.WriteLine(fiTemp.Name);
  36. i++;
  37. }
  38. return myNewFiles;
  39. }
  40. [WebMethod(Description = "返回需更新的文件的大小")]
  41. public int AllFileSize()
  42. {
  43. int filesize = 0;
  44. string[] files = Directory.GetFiles(UpdateServerPath);
  45. foreach (string file in files)
  46. {
  47. FileInfo myInfo = new FileInfo(file);
  48. filesize += (int)myInfo.Length / 1024;
  49. }
  50. return filesize;
  51. }
  52. [WebMethod(Description = "返回给定文件的字节数组")]
  53. public byte[] GetNewFile(string requestFileName)
  54. {
  55. ///得到服务器端的一个文件
  56. if (requestFileName != null || requestFileName != "")
  57. return getBinaryFile(UpdateServerPath + "\\"+requestFileName);
  58. else
  59. return null;
  60. }
  61. /// 
  62. /// 返回所给文件路径的字节数组。
  63. ///  summary>
  64. ///  name="filename"> param>
  65. ///  returns>
  66. private byte[] getBinaryFile(string filename)
  67. {
  68. if (File.Exists(filename))
  69. {
  70. try
  71. {
  72. //打开现有文件以进行读取。
  73. FileStream s = File.OpenRead(filename);
  74. return ConvertStreamToByteBuffer(s);
  75. }
  76. catch
  77. {
  78. return new byte[0];
  79. }
  80. }
  81. else
  82. {
  83. return new byte[0];
  84. }
  85. }
  86. /// 
  87. /// 把给定的文件流转换为二进制字节数组。
  88. ///  summary>
  89. ///  name="theStream"> param>
  90. ///  returns>
  91. private byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
  92. {
  93. int b1;
  94. System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
  95. while ((b1 = theStream.ReadByte()) != -1)
  96. {
  97. tempStream.WriteByte(((byte)b1));
  98. }
  99. return tempStream.ToArray();
  100. }
  101. }

本文标题:C#WebServices升级程序
文章网址:http://www.cdxtjz.cn/article/djjehci.html

联系我们

您好HELLO!
感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们, 我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
  • 电话:028- 86922220 18980695689
  • 商务合作邮箱:631063699@qq.com
  • 合作QQ: 532337155
  • 成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼

小谭建站工作室

成都小谭网站建设公司拥有多年以上互联网从业经验的团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。 我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,小谭建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!

小谭观点

相对传统的成都网站建设公司而言,小谭是互联网中的网站品牌策划,我们精于企业品牌与互联网相结合的整体战略服务。
我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。