WEB SERVICE IN ASP.NET

BASIC IN WEB SERVICES.


HOW TO ADD TWO VALUE IN WEB SERVICES USING ASP.NET IN C#


Visuval studio 2012àfile-ànew project-àsolution floder-àadd new item-àwebservices.


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

namespace ws
{
    /// <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 int Add(int a, int b)
        {
            return a + b;
        }
    }
}



You declare the value in webmehod.


AFTER RUN THE WEBSERVICES.



DESIGN YOUR WEB APPLICATION:

DEFAULT.ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table class="style1">
        <tr>
            <td class="style2">
                First Number :</td>
            <td>
                <asp:TextBox ID="txtnum1" runat="server"></asp:TextBox>
            </td>
        </tr><tr>
            <td class="style2">
                Second Number :</td>
            <td>
                <asp:TextBox ID="txtnum2" runat="server"></asp:TextBox>
            </td>
        </tr><tr>
            <td class="style2">
                &nbsp;</td>
            <td>
                <asp:Button ID="btnAdd" runat="server" onclick="btnAdd_Click" Text="Add"
                    Width="66px" />
            </td>
        </tr><tr>
            <td class="style2">
                Result :</td>
            <td>
                <asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
            </td></tr>
    </table>
    </div>
    </form>
</body>
</html>



solution floder-àadd service reference


YOU CLICK ADVANCED(Bottom an image)



YOU CLICK ADD WEB REFERENCES.



PASTE THE URL:(BEFORE YOU COPY THE WEBSERVICES URL  AND YOU CLICK THE ARROW)



YOU CLICK ADD REFERENCE.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ServiceReference1.WebService1SoapClient  w = new ServiceReference1.WebService1SoapClient();
            lblResult.Text = w.Add(Convert.ToInt32(txtnum1.Text), Convert.ToInt32(txtnum2.Text)).ToString();
        }
    }
}


(SERVICEREFERENCE1 IS YOUR ADD REFERENCE)

OUTPUT