一. 項目截圖
二. Webapplication2 __code
新建一個Webservice1.asmx文件using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Security.Cryptography;using System.Web;using System.Web.Services;namespace WebApplication2{ /// <summary> /// WebService1 的摘要說明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = Wsiprofiles.BasicPRofile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允許使用 asp.net Ajax 從腳本中調用此 Web 服務,請取消注釋以下行。 // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public bool CreateFile(string fileName) { bool isCreate = true; try { //首先設置上傳服務器文件的路徑 然后發布web服務 發布的時候要自己建一個自己知道的文件夾 "C:/NMGIS_Video/" "C:/NMGIS_Video/" fileName = Path.Combine(Server.MapPath("") + @"/Video/" + Path.GetFileName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Create, Fileaccess.ReadWrite, FileShare.ReadWrite); fs.Close(); } catch { isCreate = false; } return isCreate; } [WebMethod] public bool Append(string fileName, byte[] buffer) { bool isAppend = true; try { // fileName = Path.Combine(@"D:/ServiceEx/" + Path.GetFileName(fileName)); fileName = Path.Combine(Server.MapPath("") + @"/Video/" + Path.GetFileName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Seek(0, SeekOrigin.End); fs.Write(buffer, 0, buffer.Length); fs.Close(); } catch { isAppend = false; } return isAppend; } [WebMethod] public bool Verify(string fileName, string md5) { bool isVerify = true; try { fileName = Path.Combine(Server.MapPath("") + @"/Video/" + Path.GetFileName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); MD5CryptoServiceProvider p = new MD5CryptoServiceProvider(); byte[] md5buffer = p.ComputeHash(fs); fs.Close(); string md5Str = ""; List<string> strList = new List<string>(); for (int i = 0; i < md5buffer.Length; i++) { md5Str += md5buffer[i].ToString("x2"); } if (md5 != md5Str) isVerify = false; } catch { isVerify = false; } return isVerify; } }}三. WindowsFormsApplication1 __code
1. 添加 from四.吧啦吧啦
WebApplication2 的項目與 WindowsFormsApplication1 可以分開寫于不同的解決方案里。勿噴!抄寫.學習于 [此處](http://www.tuicool.com/articles/Z3mAvyF)新聞熱點
疑難解答