1.目的:
方便更新CS系統(參照李天平的CodeMatic中的更新功能)
2.思路:
客戶端登陸系統時調用WebService檢查服務器上的系統版本與本地系統版本比較,如果服務器端較新便提示是否自動更新。
3.實現:
A.做一WebService實現返回:
更新服務器地址
更新文件列表
最新版本號
新文件地址
B.客戶程序UpdateApp:實現比較和下載
4.代碼:
方便更新CS系統(參照李天平的CodeMatic中的更新功能)
2.思路:
客戶端登陸系統時調用WebService檢查服務器上的系統版本與本地系統版本比較,如果服務器端較新便提示是否自動更新。
3.實現:
A.做一WebService實現返回:
更新服務器地址
更新文件列表
最新版本號
新文件地址
B.客戶程序UpdateApp:實現比較和下載
4.代碼:
Code
namespace UpdateApp
{
partial class Form1
{
/// <summary>
/// 設計工具所需的變數。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
/// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form 設計工具產生的程式碼
/// <summary>
/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
///
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
//this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//this.ClientSize = new System.Drawing.Size(403, 116);
//this.MaximizeBox = false;
//this.Name = "Form1";
//this.Text = "Form1";
//this.ResumeLayout(false);
this.StatusLabel1 = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// StatusLabel1
//
this.StatusLabel1.AutoSize = true;
this.StatusLabel1.Location = new System.Drawing.Point(17, 78);
this.StatusLabel1.Name = "StatusLabel1";
this.StatusLabel1.Size = new System.Drawing.Size(146, 12);
this.StatusLabel1.TabIndex = 0;
this.StatusLabel1.Text = "连接服务器,检测更新中";
//
// progressBar1
//
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar1.Location = new System.Drawing.Point(0, 109);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(292, 20);
this.progressBar1.TabIndex = 1;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(292, 131);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.StatusLabel1);
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统更新";
this.Load += new System.EventHandler(this.Form1_Load);
//this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
}
}
namespace UpdateApp
{
partial class Form1
{
/// <summary>
/// 設計工具所需的變數。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
/// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form 設計工具產生的程式碼
/// <summary>
/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
///
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
//this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
//this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
//this.ClientSize = new System.Drawing.Size(403, 116);
//this.MaximizeBox = false;
//this.Name = "Form1";
//this.Text = "Form1";
//this.ResumeLayout(false);
this.StatusLabel1 = new System.Windows.Forms.Label();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// StatusLabel1
//
this.StatusLabel1.AutoSize = true;
this.StatusLabel1.Location = new System.Drawing.Point(17, 78);
this.StatusLabel1.Name = "StatusLabel1";
this.StatusLabel1.Size = new System.Drawing.Size(146, 12);
this.StatusLabel1.TabIndex = 0;
this.StatusLabel1.Text = "连接服务器,检测更新中";
//
// progressBar1
//
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar1.Location = new System.Drawing.Point(0, 109);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(292, 20);
this.progressBar1.TabIndex = 1;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(48, 48);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(292, 131);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.StatusLabel1);
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统更新";
this.Load += new System.EventHandler(this.Form1_Load);
//this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
}
}
Code
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using UpdateApp.com.wise;
using System.Threading;
//using UpdateApp.com.maticsoft.www;
namespace UpdateApp
{
public partial class Form1 : Form
{
//private Container components;
private string logfilename = (Application.StartupPath + @"\logInfo.txt");
private Mutex mutex;
private Thread mythread;
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private Label StatusLabel1;
public Form1()
{
InitializeComponent();
this.mutex = new Mutex(false, "UpdateApp_MUTEX");
if (!this.mutex.WaitOne(0, false))
{
this.mutex.Close();
this.mutex = null;
}
}
/// <summary>
/// DownLoad Files
/// </summary>
/// <param name="fileurl"></param>
/// <param name="localFilename"></param>
public void DownFile(string fileurl, string localFilename)
{
WebClient client = new WebClient();
client.DownloadFile(fileurl, localFilename);
client.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
base.Close();
}
try
{
this.mythread = new Thread(new ThreadStart(this.ProcUpdate));
this.mythread.Start();
//ProcUpdate();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Form1 mainForm = new Form1();
if (mainForm.mutex != null)
{
Application.Run(mainForm);
}
else if (MessageBox.Show(mainForm, "程序已经在运行!终止当前应用吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
Application.Exit();
}
}
private void ProcUpdate()
{
this.StatusLabel1.Text = "连接服务器,检测更新中";
bool flag = false;
int val = 0;
int num2 = 0;
try
{
UpServer server = new UpServer();
//UpdateApp.UpDate server = new UpDate();
if (server.GetFileList() != "")
{
string str6;
string startupPath = Application.StartupPath;
string serverUrl = server.GetServerUrl();
string newFilePath = server.GetNewFilePath();
this.SetMessage("下载文件列表");
string fileurl = serverUrl + "/wise/" + server.GetFileList();
string localFilename = startupPath + @"\Updatelist.ini";
this.DownFile(fileurl, localFilename);
StreamReader reader = File.OpenText(localFilename);
while (reader.ReadLine() != null)
{
val++;
}
reader.Close();
this.SetprogressBar1Max(val);
StreamReader reader2 = File.OpenText(localFilename);
for (int i = 1; (str6 = reader2.ReadLine()) != null; i++)
{
try
{
this.SetMessage("正在下载 " + str6);
string str7 = serverUrl + "/" + newFilePath + "/" + str6;
string str8 = startupPath + @"\" + str6;
this.DownFile(str7, str8);
num2++;
}
catch (Exception exception)
{
flag = true;
this.WriteLog(str6 + ":" + exception.Message);
}
this.SetprogressBar1Val(i);
}
this.SetMessage("下载完成。");
reader2.Close();
}
}
catch (Exception exception2)
{
string message = exception2.Message;
flag = true;
this.WriteLog(message);
}
if (flag)
{
//try
//{
// string text = "程序更新失败,建议直接在官方网站下载最新版本安装。";
// int num4 = val - num2;
// if (num4 > 0)
// {
// text = "程序更新失败" + num4.ToString() + "个文件未更新成功,建议直接在官方网站下载最新版本安装。";
// }
// if (MessageBox.Show(this, text, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
// {
// new Process();
// Process.Start("IExplore.exe", "http://www.maticsoft.com/softdown.aspx");
// }
//}
//catch
//{
// MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
//}
}
this.StartApp();
}
private void SetMessage(string msg)
{
if (this.StatusLabel1.InvokeRequired)
{
SetStatusCallback method = new SetStatusCallback(this.SetMessage);
base.Invoke(method, new object[] { msg });
}
else
{
this.StatusLabel1.Text = msg;
}
}
public void SetprogressBar1Max(int val)
{
if (this.progressBar1.InvokeRequired)
{
SetProBar1MaxCallback method = new SetProBar1MaxCallback(this.SetprogressBar1Max);
base.Invoke(method, new object[] { val });
}
else
{
this.progressBar1.Maximum = val;
}
}
public void SetprogressBar1Val(int val)
{
if (this.progressBar1.InvokeRequired)
{
SetProBar1ValCallback method = new SetProBar1ValCallback(this.SetprogressBar1Val);
base.Invoke(method, new object[] { val });
}
else
{
this.progressBar1.Value = val;
}
}
private void StartApp()
{
base.Hide();
if (MessageBox.Show(this, "程序更新成功,请关闭当前窗口重新打开应用程序。\n你想现在打开吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
string path = Application.StartupPath + @"\Wise.WinForms.exe";
if (File.Exists(path))
{
Process.Start(path);
}
}
Application.Exit();
}
public void WriteLog(string loginfo)
{
StreamWriter writer = new StreamWriter(this.logfilename, true);
writer.WriteLine(DateTime.Now.ToString() + ":" + loginfo);
writer.Close();
}
private delegate void SetProBar1MaxCallback(int val);
private delegate void SetProBar1ValCallback(int val);
private delegate void SetStatusCallback(string text);
}
}
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
using UpdateApp.com.wise;
using System.Threading;
//using UpdateApp.com.maticsoft.www;
namespace UpdateApp
{
public partial class Form1 : Form
{
//private Container components;
private string logfilename = (Application.StartupPath + @"\logInfo.txt");
private Mutex mutex;
private Thread mythread;
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private Label StatusLabel1;
public Form1()
{
InitializeComponent();
this.mutex = new Mutex(false, "UpdateApp_MUTEX");
if (!this.mutex.WaitOne(0, false))
{
this.mutex.Close();
this.mutex = null;
}
}
/// <summary>
/// DownLoad Files
/// </summary>
/// <param name="fileurl"></param>
/// <param name="localFilename"></param>
public void DownFile(string fileurl, string localFilename)
{
WebClient client = new WebClient();
client.DownloadFile(fileurl, localFilename);
client.Dispose();
}
private void Form1_Load(object sender, EventArgs e)
{
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
base.Close();
}
try
{
this.mythread = new Thread(new ThreadStart(this.ProcUpdate));
this.mythread.Start();
//ProcUpdate();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Form1 mainForm = new Form1();
if (mainForm.mutex != null)
{
Application.Run(mainForm);
}
else if (MessageBox.Show(mainForm, "程序已经在运行!终止当前应用吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
Application.Exit();
}
}
private void ProcUpdate()
{
this.StatusLabel1.Text = "连接服务器,检测更新中";
bool flag = false;
int val = 0;
int num2 = 0;
try
{
UpServer server = new UpServer();
//UpdateApp.UpDate server = new UpDate();
if (server.GetFileList() != "")
{
string str6;
string startupPath = Application.StartupPath;
string serverUrl = server.GetServerUrl();
string newFilePath = server.GetNewFilePath();
this.SetMessage("下载文件列表");
string fileurl = serverUrl + "/wise/" + server.GetFileList();
string localFilename = startupPath + @"\Updatelist.ini";
this.DownFile(fileurl, localFilename);
StreamReader reader = File.OpenText(localFilename);
while (reader.ReadLine() != null)
{
val++;
}
reader.Close();
this.SetprogressBar1Max(val);
StreamReader reader2 = File.OpenText(localFilename);
for (int i = 1; (str6 = reader2.ReadLine()) != null; i++)
{
try
{
this.SetMessage("正在下载 " + str6);
string str7 = serverUrl + "/" + newFilePath + "/" + str6;
string str8 = startupPath + @"\" + str6;
this.DownFile(str7, str8);
num2++;
}
catch (Exception exception)
{
flag = true;
this.WriteLog(str6 + ":" + exception.Message);
}
this.SetprogressBar1Val(i);
}
this.SetMessage("下载完成。");
reader2.Close();
}
}
catch (Exception exception2)
{
string message = exception2.Message;
flag = true;
this.WriteLog(message);
}
if (flag)
{
//try
//{
// string text = "程序更新失败,建议直接在官方网站下载最新版本安装。";
// int num4 = val - num2;
// if (num4 > 0)
// {
// text = "程序更新失败" + num4.ToString() + "个文件未更新成功,建议直接在官方网站下载最新版本安装。";
// }
// if (MessageBox.Show(this, text, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
// {
// new Process();
// Process.Start("IExplore.exe", "http://www.maticsoft.com/softdown.aspx");
// }
//}
//catch
//{
// MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
//}
}
this.StartApp();
}
private void SetMessage(string msg)
{
if (this.StatusLabel1.InvokeRequired)
{
SetStatusCallback method = new SetStatusCallback(this.SetMessage);
base.Invoke(method, new object[] { msg });
}
else
{
this.StatusLabel1.Text = msg;
}
}
public void SetprogressBar1Max(int val)
{
if (this.progressBar1.InvokeRequired)
{
SetProBar1MaxCallback method = new SetProBar1MaxCallback(this.SetprogressBar1Max);
base.Invoke(method, new object[] { val });
}
else
{
this.progressBar1.Maximum = val;
}
}
public void SetprogressBar1Val(int val)
{
if (this.progressBar1.InvokeRequired)
{
SetProBar1ValCallback method = new SetProBar1ValCallback(this.SetprogressBar1Val);
base.Invoke(method, new object[] { val });
}
else
{
this.progressBar1.Value = val;
}
}
private void StartApp()
{
base.Hide();
if (MessageBox.Show(this, "程序更新成功,请关闭当前窗口重新打开应用程序。\n你想现在打开吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
string path = Application.StartupPath + @"\Wise.WinForms.exe";
if (File.Exists(path))
{
Process.Start(path);
}
}
Application.Exit();
}
public void WriteLog(string loginfo)
{
StreamWriter writer = new StreamWriter(this.logfilename, true);
writer.WriteLine(DateTime.Now.ToString() + ":" + loginfo);
writer.Close();
}
private delegate void SetProBar1MaxCallback(int val);
private delegate void SetProBar1ValCallback(int val);
private delegate void SetStatusCallback(string text);
}
}
Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Windows.Forms;
namespace UpdateApp
{
public class UpdateConfig
{
public static UpdateSettings GetSettings()
{
UpdateSettings settings = null;
XmlSerializer serializer = new XmlSerializer(typeof(UpdateSettings));
try
{
FileStream stream = new FileStream(Application.StartupPath + @"\UpdateVer.xml", FileMode.Open);
settings = (UpdateSettings)serializer.Deserialize(stream);
stream.Close();
}
catch
{
settings = new UpdateSettings();
}
return settings;
}
public static void SaveSettings(UpdateSettings data)
{
string path = Application.StartupPath + @"\UpdateVer.xml";
XmlSerializer serializer = new XmlSerializer(typeof(UpdateSettings));
FileStream stream = new FileStream(path, FileMode.Create);
serializer.Serialize((Stream)stream, data);
stream.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Windows.Forms;
namespace UpdateApp
{
public class UpdateConfig
{
public static UpdateSettings GetSettings()
{
UpdateSettings settings = null;
XmlSerializer serializer = new XmlSerializer(typeof(UpdateSettings));
try
{
FileStream stream = new FileStream(Application.StartupPath + @"\UpdateVer.xml", FileMode.Open);
settings = (UpdateSettings)serializer.Deserialize(stream);
stream.Close();
}
catch
{
settings = new UpdateSettings();
}
return settings;
}
public static void SaveSettings(UpdateSettings data)
{
string path = Application.StartupPath + @"\UpdateVer.xml";
XmlSerializer serializer = new XmlSerializer(typeof(UpdateSettings));
FileStream stream = new FileStream(path, FileMode.Create);
serializer.Serialize((Stream)stream, data);
stream.Close();
}
}
}
Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace UpdateApp
{
public class UpdateSettings
{
// Fields
private string _description;
private string _serverurl;
private string _version = "1.0";
// Properties
[XmlElement]
public string Description
{
get
{
return this._description;
}
set
{
this._description = value;
}
}
[XmlElement]
public string ServerUrl
{
get
{
return this._serverurl;
}
set
{
this._serverurl = value;
}
}
[XmlElement]
public string Version
{
get
{
return this._version;
}
set
{
this._version = value;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace UpdateApp
{
public class UpdateSettings
{
// Fields
private string _description;
private string _serverurl;
private string _version = "1.0";
// Properties
[XmlElement]
public string Description
{
get
{
return this._description;
}
set
{
this._description = value;
}
}
[XmlElement]
public string ServerUrl
{
get
{
return this._serverurl;
}
set
{
this._serverurl = value;
}
}
[XmlElement]
public string Version
{
get
{
return this._version;
}
set
{
this._version = value;
}
}
}
}
Code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpdateApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<UpdateApp.Properties.Settings>
<setting name="UpdateApp_com_wise_UpServer" serializeAs="String">
<value>http://10.2.1.28/Wise/UpServer.asmx</value>
</setting>
</UpdateApp.Properties.Settings>
</applicationSettings>
</configuration>
UpServer.asmx<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpdateApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<UpdateApp.Properties.Settings>
<setting name="UpdateApp_com_wise_UpServer" serializeAs="String">
<value>http://10.2.1.28/Wise/UpServer.asmx</value>
</setting>
</UpdateApp.Properties.Settings>
</applicationSettings>
</configuration>
Code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
namespace UpdateApp.UpdateService
{
/// <summary>
/// UpServer 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class UpServer : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string GetVersion()
{
return ConfigurationManager.AppSettings["Version"];
}
[WebMethod]
public string GetServerUrl()
{
return ConfigurationManager.AppSettings["ServerUrl"];
}
[WebMethod]
public string GetFileList()
{
return ConfigurationManager.AppSettings["FileList"];
}
[WebMethod]
public string GetNewFilePath()
{
return ConfigurationManager.AppSettings["NewFilePath"];
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
namespace UpdateApp.UpdateService
{
/// <summary>
/// UpServer 的摘要描述
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class UpServer : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string GetVersion()
{
return ConfigurationManager.AppSettings["Version"];
}
[WebMethod]
public string GetServerUrl()
{
return ConfigurationManager.AppSettings["ServerUrl"];
}
[WebMethod]
public string GetFileList()
{
return ConfigurationManager.AppSettings["FileList"];
}
[WebMethod]
public string GetNewFilePath()
{
return ConfigurationManager.AppSettings["NewFilePath"];
}
}
}
Code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpdateApp.UpdateService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings/>
<system.web>
<!--
設定 compilation debug="true" 會將偵錯
符號插入編譯過的頁面。因為這樣會
影響效能,所以只有在開發期間才能將
這個值設定為 true。
-->
<compilation debug="false">
</compilation>
<!--
<authentication> 區段可以用來設定 ASP.NET
使用的安全性驗證模式,以識別連入的
使用者。
-->
<authentication mode="Windows" />
<!--
<customErrors> 區段可以用來設定
在執行要求期間發生未處理
錯誤時所要執行的動作。具體來說,
它可以讓開發人員設定要顯示的 HTML 錯誤網頁,
以取代錯誤堆疊追蹤。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<appSettings>
<!--View层程序集名称 -->
<add key="Version" value="20090927" />
<add key="ServerUrl" value= "http://10.2.1.28" />
<add key="FileList" value="FileList.txt" />
<add key="NewFilePath" value="Wise/NewFiles" />
</appSettings>
<applicationSettings>
<UpdateApp.UpdateService.Properties.Settings>
<setting name="Setting" serializeAs="String">
<value>12</value>
</setting>
<setting name="Version" serializeAs="String">
<value>090926</value>
</setting>
</UpdateApp.UpdateService.Properties.Settings>
</applicationSettings>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="UpdateApp.UpdateService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings/>
<system.web>
<!--
設定 compilation debug="true" 會將偵錯
符號插入編譯過的頁面。因為這樣會
影響效能,所以只有在開發期間才能將
這個值設定為 true。
-->
<compilation debug="false">
</compilation>
<!--
<authentication> 區段可以用來設定 ASP.NET
使用的安全性驗證模式,以識別連入的
使用者。
-->
<authentication mode="Windows" />
<!--
<customErrors> 區段可以用來設定
在執行要求期間發生未處理
錯誤時所要執行的動作。具體來說,
它可以讓開發人員設定要顯示的 HTML 錯誤網頁,
以取代錯誤堆疊追蹤。
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<appSettings>
<!--View层程序集名称 -->
<add key="Version" value="20090927" />
<add key="ServerUrl" value= "http://10.2.1.28" />
<add key="FileList" value="FileList.txt" />
<add key="NewFilePath" value="Wise/NewFiles" />
</appSettings>
<applicationSettings>
<UpdateApp.UpdateService.Properties.Settings>
<setting name="Setting" serializeAs="String">
<value>12</value>
</setting>
<setting name="Version" serializeAs="String">
<value>090926</value>
</setting>
</UpdateApp.UpdateService.Properties.Settings>
</applicationSettings>
</configuration>