0% found this document useful (0 votes)
21 views19 pages

AWT WebServices and WCF

Uploaded by

kamble2682001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views19 pages

AWT WebServices and WCF

Uploaded by

kamble2682001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Use of Web Services

CLICK ON PROJECT ADD-> NEW ITEM ->WEB SERVICES(ASMX)


Right click on project -> Add-> service refrence
Click on Discover

Click on Advanced
Click on Add Web Reference

Click on WebServices in this Solution


Click on WebService1
Click on addition

Click on Add References


Right click and update the local host

Add the Following Code :


WebService1.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

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)
{

protected void Button1_Click(object sender, EventArgs e)


{
Double a=Convert.ToDouble(TextBox1.Text);
Double b=Convert.ToDouble(TextBox2.Text);
Double res =service1.Addition(a, b);
Label1.Text = "Addition is "+res.ToString();
}

protected void Button2_Click(object sender, EventArgs e)


{
Double a = Convert.ToDouble(TextBox1.Text);
Double b = Convert.ToDouble(TextBox2.Text);
Double res = service1.Subtraction(a, b);
Label1.Text = "Subtraction is " + res.ToString();
}

protected void Button3_Click(object sender, EventArgs e)


{
Double a = Convert.ToDouble(TextBox1.Text);
Double b = Convert.ToDouble(TextBox2.Text);
Double res = service1.Multiplication(a, b);
Label1.Text = "Multiplication is " + res.ToString();
}

protected void Button4_Click(object sender, EventArgs e)


{
Double a = Convert.ToDouble(TextBox1.Text);
Double b = Convert.ToDouble(TextBox2.Text);
Double res = service1.Division(a, b);
Label1.Text = "Division is " + res.ToString();
}
}
}

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;
}

public double Division(double a, double b)


{
return (a / b);
}

public string GetData(int value)


{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)


{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}

public double Multiplication(double a, double b)


{
return a* b;
}

public double Substraction(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);

// TODO: Add your service operations here


}

// 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; }
}
}

Right click on project -> Add-> service refrence


Click on OK
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
ServiceReference1.ServiceClient svc = new ServiceReference1.ServiceClient();
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{

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();
}

protected void Button3_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox2.Text);
int b = Convert.ToInt32(TextBox3.Text);
double res =svc.Substraction(a,b);
Label1.Text = "Subtraction is " + res.ToString();
}

protected void Button4_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox2.Text);
int b = Convert.ToInt32(TextBox3.Text);
double res = svc.Division(a, b);
Label1.Text = "Division is " + res.ToString();
}

protected void Button5_Click(object sender, EventArgs e)


{
int a = Convert.ToInt32(TextBox2.Text);
int b = Convert.ToInt32(TextBox3.Text);
double res = svc.Multiplication(a, b);
Label1.Text = "Multiplication is " + res.ToString();
}
}
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy