2、在「得到」按鍵中事件寫入代碼
void btnCommit_Click(object sender, EventArgs e)
{
////實例化代理為類
WebServicesSample.Service ws = new ServiceSimpleClient.WebServicesSample.Service();
//添加返回完成事件
ws.ReverseStringCompleted += new ServiceSimpleClient.WebServicesSample.
ReverseStringCompletedEventHandler(ws_ReverseStringCompleted);
//傳入值,得到返回值
ws.ReverseStringAsync(textBox1.Text);
}
{
////實例化代理為類
WebServicesSample.Service ws = new ServiceSimpleClient.WebServicesSample.Service();
//添加返回完成事件
ws.ReverseStringCompleted += new ServiceSimpleClient.WebServicesSample.
ReverseStringCompletedEventHandler(ws_ReverseStringCompleted);
//傳入值,得到返回值
ws.ReverseStringAsync(textBox1.Text);
}
3、縮寫得到數據完成后的代碼
/// <summary>
/// 從客戶端接收數據可以通過把事件處理程序賦予ReverseStringCompleted事件來讀取。
/// ReverseStringCompletedEventArgs:在Result屬性中包含Web服務的返回數據。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ws_ReverseStringCompleted(object sender, ServiceSimpleClient.WebServicesSample.
ReverseStringCompletedEventArgs e)
{
textBox2.Text = e.Result;
}
/// 從客戶端接收數據可以通過把事件處理程序賦予ReverseStringCompleted事件來讀取。
/// ReverseStringCompletedEventArgs:在Result屬性中包含Web服務的返回數據。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ws_ReverseStringCompleted(object sender, ServiceSimpleClient.WebServicesSample.
ReverseStringCompletedEventArgs e)
{
textBox2.Text = e.Result;
}