وب سرویس در Asp.Net

در این مقاله قصد داریم توضیح دهیم که وب سرویس چیست ونحوه ساخت و استفاده آن را شرح دهیم

وب سرویس در Asp.Net

وب سرویس :

وب سرویس یک کامپوننت در وب سرور است که کاربران می توانند درخواست خود را از طریق HTTP ارسال کنند . Asp.Net شما را قادر می سازد تا وب سرویس سفارشی را تولید کنید یا نرم افزار سفارشی بسازید و آنها را از هر نرم افزار سمت کاربر اجرا کنید .

ارتباط وب سرویس از پروتوکل های استاندارد وب استفاده می کند که شامل :

HTTP

XML

SOAP

در زیر به برخی از شرایطی که ما از وب سرویس استفاده کرده ایم اشاره شده :

soap : simple Object Access Protocol.

soap یک راهی است که با فراخوانی هر متد یا انتقال به داخل فرمت XML و ارسال شده توسط HTTP استفاده میشود.

WDSL : Web Service Description Language :

WDSL شامل هر گونه جزییات مربوط به نحوه استفاده از وب سرویس و متد و تولید خواص به وسیله وب سرویس و URL که از آن متد ها و نوع داده اطلاعات استفاده شده دسترسی داشته باشید .

UDDI : Universal Description ,Discovery and  Integration

که یک وب سرویس مستقیم است در جایی که یک business می تواند ثبت شود و برای وب سرویس جستجو کند .

Discovery or Disco Files :

فایل های Disco اغلب به سورس WDSL اشاره می کنند و در این اشاره ها که به وب سرویس حقیقی اشاره می کنند زمانی که یک جستجو برای وب سرویس شروع میشود .

اکنون ما می خواهیم نحوه ساخت و به کار گیری یه وب سرویس در Asp.Net توضیح دهیم .در ادامه جدول اطلاعات در Design Mode از وب سرویسی که می خواهیم به آن متصل کنیم که شامل تصویر زیر میباشد :

و اسکریپت جدول اطلاعات شامل کد زیر می باشد :


    CREATE TABLE [dbo].[Employee](  
        [Emp_ID] [int] IDENTITY(1,1) NOT NULL,  
        [Name] [varchar](50) NULL,  
        [Designation] [varchar](50) NULL,  
        [City] [varchar](50) NULL,  
        [State] [varchar](50) NULL,  
        [Country] [varchar](50) NULL,  
     CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED   
    (  
        [Emp_ID] ASC  
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]  
    ) ON [PRIMARY]  
    GO  

و در ادامه اطلاعات جدول شامل زیر میباشد :

اکنون ویژوال استودیو خود را اجرا کنید select file > New Web Site > Asp.Net Web Serveice.

حالا Service.cs داخل App_Code را اجرا کنید برای نوشتن متد وب :

کد های App_Code/Service.cs شامل زیر میباشد :


Reader Level:
Articles
[ASP.NET Programming]
Web Services in ASP.Net C#
By Rahul Saxena on Feb 16, 2015
In this article I am going to explain what a Web Service is, how to create one and how to consume it.

    Tweet

    3
    6
    1856

Download Files:

    SearchUserService.zip
    |
    ManageEmployee.zip

 

Web Services

Web Services are components on a web server that a client application can call by making HTTP requests across the Web. ASP.NET enables you to create custom Web Services or to use built-in application services and call these services from any client application.

Web Services communicate using the following standard web protocols and data formats:

    HTTP
    XML
    SOAP 

The following are some terms we often use with Web Services.

SOAP: Simple Object Access Protocol. SOAP is way by which method calls are translated into XML format and sent via HTTP.

WSDL: Web Service Description Language. WSDL contains every detail regarding the use of Web Services and method and properties provided by Web Service and URLs from which those methods can be accessed and data types used.

UDDI: Universal Description, Discovery and Integration (UDDI) is a directory service where businesses can register and search for Web Services.

Discovery or .Disco Files: The DISCO file typically points to a WSDL source that in turn points to the actual Web Service when one searches for the Web Services.

Now we will see how to create and consume Web Services in ASP.Net C#. The following is my data table in Design Mode from which I will fetch data using the Web Service:

table design
                                       Image 1.

The following is the script of my data table:

    CREATE TABLE [dbo].[Employee](  
        [Emp_ID] [int] IDENTITY(1,1) NOT NULL,  
        [Name] [varchar](50) NULL,  
        [Designation] [varchar](50) NULL,  
        [City] [varchar](50) NULL,  
        [State] [varchar](50) NULL,  
        [Country] [varchar](50) NULL,  
     CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED   
    (  
        [Emp_ID] ASC  
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]  
    ) ON [PRIMARY]  
    GO  

The following is the data in my table:

table
                                                                              Image 2.

Now open Visual Studio then select File -> New Web Site-> ASP.NET Web Service.

Web Service
                                                                        Image 3.

Now open Service.cs inside the App_Code folder to write your WebMethod as in the following:

WebMethod
                                                                        Image 4.

The following is the App_Code/Service.cs:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Services;  
    using System.Data.SqlClient;  
    using System.Data;  
    using System.Xml;  
      
    [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 XmlElement GetEmployeeSearchResult(string EMP_Name)  
        {  
            using (SqlConnection con = new SqlConnection(@"Data Source=INDIA\MSSQLServer2k8; Initial Catalog=EmployeeManagement; Uid=sa; pwd=india;"))  
            {  
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM EMPLOYEE WHERE Name like @EMP_Name+'%'", con))  
                {  
                    con.Open();  
                    cmd.Parameters.AddWithValue("@EMP_Name", EMP_Name);  
                    cmd.ExecuteNonQuery();  
                    SqlDataAdapter da = new SqlDataAdapter(cmd);  
                      
                    DataSet ds = new DataSet();  
                    da.Fill(ds);  
                    con.Close();  
                       
                    XmlDataDocument xmldata = new XmlDataDocument(ds);  
                    XmlElement xmlElement = xmldata.DocumentElement;  
                    return xmlElement;  
                }  
            }  
        }  
    }  

حالا وب سرویس خود را چک کنید . پس باید نرم افزار خود را اجرا کنید :

 

سپس روی نام متد خود کلیک کنید :

سپس وب سرویس تولید شده را اجرا می کنیم .پس باید یک Asp.Net Application جدید بسازیم .

بر روی Application در Solution Explorer راست کلیک کرده و Add Web Service Refrence را انتخاب کنید .

Url وب سرویس مورد نظر خود را وارد کنید  و روی Go  کلیک کنید , سپس روی دکمه Add Refrence کلیک کنید .

کد های صفحه aspx :


Reader Level:
Articles
[ASP.NET Programming]
Web Services in ASP.Net C#
By Rahul Saxena on Feb 16, 2015
In this article I am going to explain what a Web Service is, how to create one and how to consume it.

    Tweet

    3
    6
    1856

Download Files:

    SearchUserService.zip
    |
    ManageEmployee.zip

 

Web Services

Web Services are components on a web server that a client application can call by making HTTP requests across the Web. ASP.NET enables you to create custom Web Services or to use built-in application services and call these services from any client application.

Web Services communicate using the following standard web protocols and data formats:

    HTTP
    XML
    SOAP 

The following are some terms we often use with Web Services.

SOAP: Simple Object Access Protocol. SOAP is way by which method calls are translated into XML format and sent via HTTP.

WSDL: Web Service Description Language. WSDL contains every detail regarding the use of Web Services and method and properties provided by Web Service and URLs from which those methods can be accessed and data types used.

UDDI: Universal Description, Discovery and Integration (UDDI) is a directory service where businesses can register and search for Web Services.

Discovery or .Disco Files: The DISCO file typically points to a WSDL source that in turn points to the actual Web Service when one searches for the Web Services.

Now we will see how to create and consume Web Services in ASP.Net C#. The following is my data table in Design Mode from which I will fetch data using the Web Service:

table design
                                       Image 1.

The following is the script of my data table:

    CREATE TABLE [dbo].[Employee](  
        [Emp_ID] [int] IDENTITY(1,1) NOT NULL,  
        [Name] [varchar](50) NULL,  
        [Designation] [varchar](50) NULL,  
        [City] [varchar](50) NULL,  
        [State] [varchar](50) NULL,  
        [Country] [varchar](50) NULL,  
     CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED   
    (  
        [Emp_ID] ASC  
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]  
    ) ON [PRIMARY]  
    GO  

The following is the data in my table:

table
                                                                              Image 2.

Now open Visual Studio then select File -> New Web Site-> ASP.NET Web Service.

Web Service
                                                                        Image 3.

Now open Service.cs inside the App_Code folder to write your WebMethod as in the following:

WebMethod
                                                                        Image 4.

The following is the App_Code/Service.cs:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Services;  
    using System.Data.SqlClient;  
    using System.Data;  
    using System.Xml;  
      
    [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 XmlElement GetEmployeeSearchResult(string EMP_Name)  
        {  
            using (SqlConnection con = new SqlConnection(@"Data Source=INDIA\MSSQLServer2k8; Initial Catalog=EmployeeManagement; Uid=sa; pwd=india;"))  
            {  
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM EMPLOYEE WHERE Name like @EMP_Name+'%'", con))  
                {  
                    con.Open();  
                    cmd.Parameters.AddWithValue("@EMP_Name", EMP_Name);  
                    cmd.ExecuteNonQuery();  
                    SqlDataAdapter da = new SqlDataAdapter(cmd);  
                      
                    DataSet ds = new DataSet();  
                    da.Fill(ds);  
                    con.Close();  
                       
                    XmlDataDocument xmldata = new XmlDataDocument(ds);  
                    XmlElement xmlElement = xmldata.DocumentElement;  
                    return xmlElement;  
                }  
            }  
        }  
    }  

Now to check your Web Service. So run your application:

check your Web Service
                                                                           Image 5.

Now click on your Method name:

get employee result
                                                                        Image 6.

Run your application
                                                                              Image 7.

Now to consume this Web Service. So create a new ASP.NET application.

application
                                                                        Image 8.

Now right-click on your application in the Solution Explorer then select Add Web Reference.

add web reference
                              Image 9.

Type your Web Service URL and click GO. Then click on the Add Reference button:

Add Reference
                                                                     Image 10.

The following is the aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head>  
    <body>  
        <form id="form1" runat="server">  
        <div>  
            <table style="border: solid 15px blue; width: 100%; vertical-align: central;">  
                <tr>  
                    <td style="padding-left: 20px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue;  
                        text-align: center; font-family: Verdana; font-size: 20pt; color: red;">  
                        Web Services In ASP.NET C#  
                    </td>  
                </tr>  
                <tr>  
                    <td style="background-color: skyblue; text-align: center; font-family: Verdana; font-size: 14pt;  
                        color: red;">  
                        <b>Enter Employee Name:</b>  
                        <asp:TextBox ID="txtEmpName" runat="server"></asp:TextBox>  
                        <asp:Button ID="btnSearchEmployee" runat="server" Text="Search Employee" OnClick="btnSearchEmployee_Click" />  
                    </td>  
                </tr>  
                <tr>  
                    <td>  
                        <table style="width: 80%; text-align: center; vertical-align: central;">  
                            <tr>  
                                <td style="text-align: left;">  
                                    <asp:GridView ID="GridViewEmployee" runat="server" AutoGenerateColumns="False" Width="100%"  
                                        BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"  
                                        CellPadding="4">  
                                        <Columns>  
                                            <asp:BoundField DataField="Name" HeaderText="Employee Name" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="Designation" HeaderText="Designation" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="City" HeaderText="City" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="State" HeaderText="State" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                        </Columns>  
                                        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />  
                                        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />  
                                        <PagerStyle ForeColor="#003399" HorizontalAlign="Left" BackColor="#99CCCC" />  
                                        <RowStyle BackColor="White" ForeColor="#003399" />  
                                        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />  
                                    </asp:GridView>  
                                </td>  
                            </tr>  
                        </table>  
                    </td>  
                </tr>  
            </table>  
        </div>  
        </form>  
    </body>  
    </html> 

کد های صفحه aspx.cs :


Reader Level:
Articles
[ASP.NET Programming]
Web Services in ASP.Net C#
By Rahul Saxena on Feb 16, 2015
In this article I am going to explain what a Web Service is, how to create one and how to consume it.

    Tweet

    3
    6
    1856

Download Files:

    SearchUserService.zip
    |
    ManageEmployee.zip

 

Web Services

Web Services are components on a web server that a client application can call by making HTTP requests across the Web. ASP.NET enables you to create custom Web Services or to use built-in application services and call these services from any client application.

Web Services communicate using the following standard web protocols and data formats:

    HTTP
    XML
    SOAP 

The following are some terms we often use with Web Services.

SOAP: Simple Object Access Protocol. SOAP is way by which method calls are translated into XML format and sent via HTTP.

WSDL: Web Service Description Language. WSDL contains every detail regarding the use of Web Services and method and properties provided by Web Service and URLs from which those methods can be accessed and data types used.

UDDI: Universal Description, Discovery and Integration (UDDI) is a directory service where businesses can register and search for Web Services.

Discovery or .Disco Files: The DISCO file typically points to a WSDL source that in turn points to the actual Web Service when one searches for the Web Services.

Now we will see how to create and consume Web Services in ASP.Net C#. The following is my data table in Design Mode from which I will fetch data using the Web Service:

table design
                                       Image 1.

The following is the script of my data table:

    CREATE TABLE [dbo].[Employee](  
        [Emp_ID] [int] IDENTITY(1,1) NOT NULL,  
        [Name] [varchar](50) NULL,  
        [Designation] [varchar](50) NULL,  
        [City] [varchar](50) NULL,  
        [State] [varchar](50) NULL,  
        [Country] [varchar](50) NULL,  
     CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED   
    (  
        [Emp_ID] ASC  
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]  
    ) ON [PRIMARY]  
    GO  

The following is the data in my table:

table
                                                                              Image 2.

Now open Visual Studio then select File -> New Web Site-> ASP.NET Web Service.

Web Service
                                                                        Image 3.

Now open Service.cs inside the App_Code folder to write your WebMethod as in the following:

WebMethod
                                                                        Image 4.

The following is the App_Code/Service.cs:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Services;  
    using System.Data.SqlClient;  
    using System.Data;  
    using System.Xml;  
      
    [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 XmlElement GetEmployeeSearchResult(string EMP_Name)  
        {  
            using (SqlConnection con = new SqlConnection(@"Data Source=INDIA\MSSQLServer2k8; Initial Catalog=EmployeeManagement; Uid=sa; pwd=india;"))  
            {  
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM EMPLOYEE WHERE Name like @EMP_Name+'%'", con))  
                {  
                    con.Open();  
                    cmd.Parameters.AddWithValue("@EMP_Name", EMP_Name);  
                    cmd.ExecuteNonQuery();  
                    SqlDataAdapter da = new SqlDataAdapter(cmd);  
                      
                    DataSet ds = new DataSet();  
                    da.Fill(ds);  
                    con.Close();  
                       
                    XmlDataDocument xmldata = new XmlDataDocument(ds);  
                    XmlElement xmlElement = xmldata.DocumentElement;  
                    return xmlElement;  
                }  
            }  
        }  
    }  

Now to check your Web Service. So run your application:

check your Web Service
                                                                           Image 5.

Now click on your Method name:

get employee result
                                                                        Image 6.

Run your application
                                                                              Image 7.

Now to consume this Web Service. So create a new ASP.NET application.

application
                                                                        Image 8.

Now right-click on your application in the Solution Explorer then select Add Web Reference.

add web reference
                              Image 9.

Type your Web Service URL and click GO. Then click on the Add Reference button:

Add Reference
                                                                     Image 10.

The following is the aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head>  
    <body>  
        <form id="form1" runat="server">  
        <div>  
            <table style="border: solid 15px blue; width: 100%; vertical-align: central;">  
                <tr>  
                    <td style="padding-left: 20px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue;  
                        text-align: center; font-family: Verdana; font-size: 20pt; color: red;">  
                        Web Services In ASP.NET C#  
                    </td>  
                </tr>  
                <tr>  
                    <td style="background-color: skyblue; text-align: center; font-family: Verdana; font-size: 14pt;  
                        color: red;">  
                        <b>Enter Employee Name:</b>  
                        <asp:TextBox ID="txtEmpName" runat="server"></asp:TextBox>  
                        <asp:Button ID="btnSearchEmployee" runat="server" Text="Search Employee" OnClick="btnSearchEmployee_Click" />  
                    </td>  
                </tr>  
                <tr>  
                    <td>  
                        <table style="width: 80%; text-align: center; vertical-align: central;">  
                            <tr>  
                                <td style="text-align: left;">  
                                    <asp:GridView ID="GridViewEmployee" runat="server" AutoGenerateColumns="False" Width="100%"  
                                        BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"  
                                        CellPadding="4">  
                                        <Columns>  
                                            <asp:BoundField DataField="Name" HeaderText="Employee Name" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="Designation" HeaderText="Designation" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="City" HeaderText="City" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="State" HeaderText="State" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                            <asp:BoundField DataField="Country" HeaderText="Country" HeaderStyle-HorizontalAlign="Left">  
                                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle>  
                                            </asp:BoundField>  
                                        </Columns>  
                                        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />  
                                        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />  
                                        <PagerStyle ForeColor="#003399" HorizontalAlign="Left" BackColor="#99CCCC" />  
                                        <RowStyle BackColor="White" ForeColor="#003399" />  
                                        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />  
                                    </asp:GridView>  
                                </td>  
                            </tr>  
                        </table>  
                    </td>  
                </tr>  
            </table>  
        </div>  
        </form>  
    </body>  
    </html>  

The following is the aspx.cs:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using System.Data;  
    using System.Xml;  
      
    public partial class _Default : System.Web.UI.Page   
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                BindEmployee("");  
            }  
        }  
      
        protected void BindEmployee(string Emp_Name)  
        {  
            localhost.Service obj = new localhost.Service();  
            DataSet ds = new DataSet();  
            XmlElement exElement = obj.GetEmployeeSearchResult(Emp_Name);  
            if (exElement != null)  
            {  
                XmlNodeReader nodeReader = new XmlNodeReader(exElement);  
                ds.ReadXml(nodeReader, XmlReadMode.Auto);  
                GridViewEmployee.DataSource = ds;  
                GridViewEmployee.DataBind();  
            }  
            else  
            {  
                GridViewEmployee.DataSource = null;  
                GridViewEmployee.DataBind();  
            }  
        }  
        protected void btnSearchEmployee_Click(object sender, EventArgs e)  
        {  
            BindEmployee(txtEmpName.Text);  
        }  
    }  

اکنون نرم افزار خود را اجرا کنید :

نام را وارد کنید و روی جستجو کلیک کنید :

 

فایل های ضمیمه