Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Please any one explain me how to create a wcf service for the stored procedures. I have created a stored procedures namely Location and PopSublocation. For getting the Locations in the location dropdown list I have written the code like...

C#
protected void LocationBind()
        {
            SqlConnection conn = new SqlConnection(connstr);

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Location";

            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            ddlLocation.DataSource = reader;
            ddlLocation.DataTextField = "Location";
            ddlLocation.DataValueField = "LocationID";
            ddlLocation.DataBind();
            ddlLocation.Items.Insert(0, new ListItem("Select", "-1"));
            conn.Close();
            reader.Close();
        }



Then for populating the sublocation in another drop-down list i have created one more stored procedure(PopSublocation).It will take locationID as input according to the particular locationID it is going to populate the appropriate subLocation. The below code i have written to populate the Sublocation list in the dropdown.

C#
protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e)
       {
           SqlConnection conn = new SqlConnection(connstr);
           SqlCommand cmd = new SqlCommand();
           cmd.Connection = conn;
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.CommandText = "PopSublocation";
           cmd.Parameters.AddWithValue("@location", Convert.ToInt32(ddlLocation.SelectedValue));
           ddlSublocation.Items.Insert(0, new ListItem("Select", "-1"));
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataSet ds = new DataSet();
           da.Fill(ds);
           ddlSublocation.DataSource = ds.Tables[0];
           ddlSublocation.DataTextField = "Sublocation";
           ddlSublocation.DataValueField = "Sublocation";
           ddlSublocation.DataBind();

                      
       }


Now i need to create a wcf service for both stored procedure and call them in the program. Please help me out for this, i am very new for this concept. Sorry for the inconvenience for any errors or not understanding.
Posted

1 solution

This should help you get started.

A Step by Step WCF Small Program For Beginners [^]

I assume that you know how to create database connections. If you don't follow this
DAL Class and Transact-SQL Generator for C# and VB.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900