Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the C # Web Services upgrade Program

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to implement the C# Web Services upgrade program. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

This paper introduces an upgrade program with C # Web Services. Upgrading the program through C # Web Services is as simple as reading and writing native files. So I just gave the code.

Part of the code of the C# Web Services upgrade program:

Using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.IO; [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service: System.Web.Services.WebService {public Service () {/ / if you use the designed component, uncomment the following line / / InitializeComponent () } / summary > private const string UpdateServerPath = "d:\\ Debug"; [WebMethod (Description = "return the version number of the program on the server")] public string ServerVer () {return "4.0";} [WebMethod (Description = "return the file to be updated")] public string [] NewFiles () {DirectoryInfo di = new DirectoryInfo (UpdateServerPath); FileInfo [] fi = di.GetFiles () Int intFiles= fi.Length; string [] myNewFiles = new string [intFiles]; int I = 0; foreach (FileInfo fiTemp in fi) {myNewFiles [I] = fiTemp.Name; System.Diagnostics.Debug.WriteLine (fiTemp.Name); iTunes;} return myNewFiles;} [WebMethod (Description = "return the size of the file to be updated")] public int AllFileSize () {int filesize = 0; string [] files = Directory.GetFiles (UpdateServerPath) Foreach (string file in files) {FileInfo myInfo = new FileInfo (file); filesize + = (int) myInfo.Length / 1024;} return filesize;} [WebMethod (Description = "return a byte array of a given file")] public byte [] GetNewFile (string requestFileName) {/ / get a file if (requestFileName! = null | | requestFileName! = ") return getBinaryFile (UpdateServerPath +"\ "+ requestFileName) on the server side; else return null } / returns a byte array of the given file path. / / summary > / / param > / / returns > private byte [] getBinaryFile (string filename) {if (File.Exists (filename)) {try {/ / Open an existing file for reading. FileStream s = File.OpenRead (filename); return ConvertStreamToByteBuffer (s);} catch {return new byte [0];}} else {return new byte [0];}} / converts the given file stream into a binary byte array. / / summary > / / param > / / returns > private byte [] ConvertStreamToByteBuffer (System.IO.Stream theStream) {int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream (); while ((b1 = theStream.ReadByte ())! =-1) {tempStream.WriteByte (byte) b1));} return tempStream.ToArray () }} this is the end of the article on "how to implement the C # Web Services upgrade program". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report