WebService




file->new website->ASP.NET web service  language: C#

using System;
using System.Linq;
using System.Web;
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 Service : System.Web.Services.WebService
{
    public Service () {

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

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }
    [WebMethod]
    public double f_c(double t)
    {
        return(((t-32)*5)/9);
    }
    [WebMethod]
    public double c_f(double t)
    {
        return (((t*9)/5)+32);
    }


}


save and run (press F5)




file->new website->ASP.NET web service  language: C#

design 




add web reference:



Website
using System;
using System.Configuration;
using System.Data;
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)
    {
        TextBox1.Focus();
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
       
       
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        double z;
        temp.Service obj = new temp.Service();
        if (TextBox1.Text=="")
        {
            Type cstype = this.GetType();
            ClientScriptManager cs = Page.ClientScript;
            if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
            {
                String cstext = "alert('Please Enter Value');";
                cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);

            }
        }
        else
        {
            if (DropDownList1.Text == "Fahrenheit to Celsius")
            {
                z = obj.f_c(double.Parse(TextBox1.Text));

                Label2.Text = z.ToString() + "  C";
            }
            else if (DropDownList1.Text == "Celsius to Fahrenheit")
            {
                z = obj.c_f(double.Parse(TextBox1.Text));
                Label2.Text = z.ToString() + "  F";
            }
            else
            {
                Type cstype = this.GetType();
                ClientScriptManager cs = Page.ClientScript;
                if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                {
                    String cstext = "alert('Please Select Conversion');";
                    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);

                }
            }
        }

    }
}

save and run (press F5)
output




0 Response to "WebService"

Post a Comment



Your IP Address is:

Browser: