Monday, April 26, 2010

WebServices in ASP.NET




A Simple Example To run a WebServices :
=====================================================================================
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Factorial : System.Web.Services.WebService
{
public Factorial()
{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public int FindFact(int x)
{
int a=1;
while (x != 0)
{
a = a * x;
x--;
}
return a;

}

}
=================================================================================

Client Program :


using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void btnClick_Click(object sender, EventArgs e)
{
Factorial Fct = new Factorial();
int Res = Fct.FindFact(Convert.ToInt32(txtFact.Text));
txtShowFact.Text = Convert.ToString(Res);
}
}


===========================================================================

Output:


==============================================================================

Monday, April 5, 2010

Introduction to Delegate

A delegate is an object that can refer to a method. Delegate object contain references to methods that need to be invoked instead of containing actual method names.

Features of Delegate

q Methods can be passed as parameters to a delegate. In addition, a delegate can accept a block of code as a parameter. Such blocks are referred to as anonymous methods because they have no method name.

q A delegate can invoke multiple methods simultaneously. And this is known as multicasting.

q A delegate can encapsulate static methods.