asyncwebservice.cs

来自「《ASP.NET 2.0 XML 高级编程(第3版)》 《ASP.NET 2.」· CS 代码 · 共 44 行

CS
44
字号
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AsyncWebService : System.Web.Services.WebService {

	public delegate string SleepForSpecificDurationAsyncStub(int milliseconds);

	public string SleepForSpecificDuration(int milliseconds)
	{
		System.Threading.Thread.Sleep(milliseconds);
		return "Completed";
	}

	public class WebServiceState
	{
		public object PreviousState;
		public SleepForSpecificDurationAsyncStub AsyncStub;
	}

	[WebMethod]
	public IAsyncResult BeginSleepForSpecificDuration(
		int milliseconds, AsyncCallback callback, object s)
	{
		SleepForSpecificDurationAsyncStub stub = new SleepForSpecificDurationAsyncStub(SleepForSpecificDuration);
		WebServiceState state = new WebServiceState();
		state.PreviousState = s;
		state.AsyncStub = stub;
		return stub.BeginInvoke(milliseconds, callback, state);
	}

	[System.Web.Services.WebMethod]
	public string EndSleepForSpecificDuration(IAsyncResult call)
	{
		WebServiceState state = (WebServiceState)call.AsyncState;
		return state.AsyncStub.EndInvoke(call);
	}    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?