chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO.Compression;
|
||||
|
||||
[WebService(Namespace = "http://www.maolaoda.com/CRAXFileTransfer")]
|
||||
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
public class CRAXFileTransfer : System.Web.Services.WebService
|
||||
{
|
||||
public CRAXFileTransfer()
|
||||
{
|
||||
//Uncomment the following line if using designed components
|
||||
//InitializeComponent();
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public GetFileResponse GetFile(string filename, bool compress)
|
||||
{
|
||||
GetFileResponse response = new GetFileResponse();
|
||||
try
|
||||
{
|
||||
response.FileName = filename;
|
||||
|
||||
if (compress)
|
||||
{
|
||||
FileStream readStream = File.Open(Server.MapPath(filename), FileMode.Open, FileAccess.Read);
|
||||
byte[] buffer = new byte[readStream.Length];
|
||||
int count = readStream.Read(buffer, 0, buffer.Length);
|
||||
readStream.Close();
|
||||
if (count != buffer.Length)
|
||||
{
|
||||
response.Message = "Unable to read data from " + filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
GZipStream compressStream = new GZipStream(outputStream, CompressionMode.Compress, true);
|
||||
compressStream.Write(buffer, 0, buffer.Length);
|
||||
compressStream.Flush();
|
||||
compressStream.Close();
|
||||
response.FileContents = outputStream.GetBuffer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response.FileContents = File.ReadAllBytes(Server.MapPath(filename));
|
||||
}
|
||||
|
||||
response.Message = "OK";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response.Message = "ERROR:" + ex.Message;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
[XmlRoot("getFileResponse", Namespace = "http://www.maolaoda.com/CRAXFileTransfer")]
|
||||
public class GetFileResponse
|
||||
{
|
||||
[XmlElement("fileName", IsNullable = false)]
|
||||
public string FileName;
|
||||
|
||||
[XmlElement("message", IsNullable = false)]
|
||||
public string Message;
|
||||
|
||||
[XmlElement("fileData", IsNullable = true)]
|
||||
public byte[] FileContents;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user