how to use HttpSimpleClientProtocol.BeginInvoke
HttpSimpleClientProtocol.BeginInvoke from the below link:
HttpSimpleClientProtocol.BeginInvoke
And I try it like below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Xml.Serialization;
using System.Web.Services.Protocols;
[XmlRootAttribute("int", Namespace = "http://MyMath/", IsNullable = false)]
public class Math : HttpGetClientProtocol
{
public Math()
{
this.Url = "http://www.contoso.com/math.asmx";
}
[HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader),
typeof(System.Web.Services.Protocols.UrlParameterWriter))]
public int Add(int num1, int num2)
{
return ((int)(this.Invoke("Add", ((this.Url) + ("/Add")),
new object[] { num1, num2 })));
}
public IAsyncResult BeginAdd(int num1, int num2, AsyncCallback callback, object asyncState)
{
return this.BeginInvoke("Add", ((this.Url) + ("/Add")),
new object[] { num1, num2 }, callback, asyncState);
}
public int EndAdd(IAsyncResult asyncResult)
{
return ((int)(this.EndInvoke(asyncResult)));
}
}
namespace Test_Async
{
public partial class MyMath : System.Web.UI.Page
{
// protected IAsyncResult BeginInvoke(string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState);
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyMath.aspx.cs" Inherits="Test_Async.MyMath" %>
<!DOCTYPE html>
<html>
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Call the Add XML Web service method asynchronously.
IAsyncResult result = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), null, null);
// Wait for the asynchronous call to complete.
result.AsyncWaitHandle.WaitOne();
// Complete the asynchronous call to the Add XML Web service method.
int total = math.EndAdd(result);
Total.Text = "Total: " + total.ToString();
}
</script>
<body>
<form action="MathClient.aspx" runat="server">
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1:
<asp:TextBox ID="Num1" runat="server" />
+
Number 2:
<asp:TextBox ID="Num2" runat="server" />
=
<asp:Button Text="Total" OnClick="EnterBtn_Click" runat="server" />
<p>
<asp:Label ID="Total" runat="server" />
</form>
</body>
</html>
using System;
public class Math
{
[WebMethod]
public int Add(int num1, int num2)
{
return num1 + num2;
}
}
I don't know, did I use the code in the right place?