1. 程式人生 > >NET 平臺下的WebService

NET 平臺下的WebService

public partial class SOAP : System.Web.UI.Page

{

protected string loginInfo = string.Empty;

protected void Page_Load(object sender, EventArgs e)

{

BackgroundWorker bw = new BackgroundWorker();//開啟單獨執行緒執行操作

bw.DoWork += new DoWorkEventHandler(bw_DoWork);//指定要作什麼

//當後臺操作完之後

bw.RunWorkerCompleted += new

RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

//開始後臺操作

bw.RunWorkerAsync();

}

void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

{

loginInfo = e.Result.ToString();//得到值,如果是可以是DataSet,List<userinfo>等型別

}

void bw_DoWork(object sender, DoWorkEventArgs e)

{

using (ServiceReference1.WebService1SoapClient

client = new ServiceReference1.WebService1SoapClient())

{

ServiceReference1.UserInfo info = new ServiceReference1.UserInfo();

info.Name = "admin";

info.Pwd = "admin";

e.Result = client.GetInfo(info);

}

}

}