?? upload.asmx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Services;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Dime;
namespace BufferedUpload.Upload {
[WebService(Namespace="http://yourdomain.com/upload/")]
public class Upload : System.Web.Services.WebService
{
/// <summary>
/// This method initializes a buffered upload. It creates a temporary file on the
/// server's temp directory and a session object that references the temp file. It returns
/// a string value representing the InstanceId of the buffered upload. This id should be
/// passed to the proceding calls to AppendChunk(), Save(), and Close() methods.
/// </summary>
[WebMethod(EnableSession=true)]
public string Initialize(string Filename, bool Overwrite)
{
return new Instance(Filename, Overwrite).Initialize().Id;
}
/// <summary>
/// This method appends a dime attachment to an upload in progress.
/// </summary>
/// <param name="InstanceId">The string returned by Initialize() method.</param>
/// <param name="offset">The offset at which to start writing.</param>
/// <param name="length">The size of the buffer.</param>
[WebMethod(EnableSession=true)]
public void AppendChunk(string InstanceId, long offset, int bufferSize)
{
Instance i = Instance.GetInstanceById(InstanceId);
if (i != null)
{
if(RequestSoapContext.Current == null || RequestSoapContext.Current.Attachments.Count == 0)
throw new SoapFormatException("No SOAP attachments included in message");
Stream dimeStream = RequestSoapContext.Current.Attachments[0].Stream;
byte[] buffer = new byte[dimeStream.Length];
dimeStream.Read(buffer, 0, buffer.Length);
dimeStream.Close();
i.AppendChunk(buffer, offset, bufferSize);
}
else
Instance.CustomSoapException("Instance Not Found", InstanceId);
}
/// <summary>
/// This method removes the upload instance from session state .
/// </summary>
/// <param name="InstanceId">The string returned by Initialize() method.</param>
[WebMethod(EnableSession=true)]
public void RemoveInstance(string InstanceId)
{
Instance i = Instance.GetInstanceById(InstanceId);
if(i != null)
i.RemoveFromSession();
// else: nothing to remove anyway, so don't report any errors.
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -