AWT WebServices and WCF
AWT WebServices and WCF
Click on Advanced
Click on Add Web Reference
namespace WebServices_C23047
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public Double Addition(double a,double b)
{
return a + b;
}
[WebMethod]
public Double Subtraction(double a, double b)
{
return a - b;
}
[WebMethod]
public Double Multiplication(double a, double b)
{
return a * b;
}
[WebMethod]
public Double Division(double a, double b)
{
return (a / b);
}
}
}
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebServices_C23047
{
public partial class WebForm1 : System.Web.UI.Page
{
localhost.WebService1 service1 = new localhost.WebService1();
protected void Page_Load(object sender, EventArgs e)
{
Output:
Windows Communication Foundation
Default.aspx
Service.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service" in code,
svc and config file together.
public class Service : IService
{
public double Addition(double a, double b)
{
return a + b;
}
IService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in
both code and config file together.
[ServiceContract]
public interface IService
{
[OperationContract]
Double Addition(double a,double b);
[OperationContract]
Double Substraction(double a, double b);
[OperationContract]
Double Multiplication(double a, double b);
[OperationContract]
Double Division(double a, double b);
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
int a=(int)Convert.ToInt64(TextBox1.Text);
Label1.Text=svc.GetData(a);
}
protected void Button2_Click(object sender, EventArgs e)
{
int a=Convert.ToInt32(TextBox2.Text);
int b=Convert.ToInt32(TextBox3.Text);
double res = svc.Addition(a,b);
Label1.Text = "Addition is " + res.ToString();
}