Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Webservice.asmx
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// 
/// Summary description for WebService1
/// 
[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 WebService1 : System.Web.Services.WebService {

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    //Web method for bind country
    [WebMethod]
    public CascadingDropDownNameValue[] BindCountry(string knownCategoryValues, string category)
    {
        DataSet ds = new DataSet();
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from country", conn);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        cmd.ExecuteNonQuery();
        adp.Fill(ds);
        conn.Close();
        List CountryDetails = new List();
        foreach (DataRow DR in ds.Tables[0].Rows)
        {
            string id = DR["id"].ToString();
            string Country = DR["Country"].ToString();
            CountryDetails.Add(new CascadingDropDownNameValue(Country, id));
        }
        return CountryDetails.ToArray();
    }
    //Web method for bind state
    [WebMethod]
    public CascadingDropDownNameValue[] BindState(string knownCategoryValues, string category)
    {
        DataSet ds = new DataSet();
        int id;
        StringDictionary CountryDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        id = Convert.ToInt32(CountryDetails["Country"]);
        conn.Open();
        SqlCommand cmd = new SqlCommand("select * from State where id=@id", conn);
        cmd.Parameters.AddWithValue("@id", id);
        cmd.ExecuteNonQuery();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        adp.Fill(ds);
        conn.Close();
        List StateDetails = new List();
        foreach (DataRow DR in ds.Tables[0].Rows)
        {
            string Sid = DR["Sid"].ToString();
            string StateName = DR["StateName"].ToString();
            StateDetails.Add(new CascadingDropDownNameValue(StateName, Sid));
        }
        return StateDetails.ToArray();
    }
    //Web method for bind city
    [WebMethod]
    public CascadingDropDownNameValue[] BindCity(string knownCategoryValues, string category)
    {
        DataSet ds = new DataSet();
        int Sid;
        StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        Sid = Convert.ToInt32(statedetails["State"]);
        conn.Open();
        SqlCommand cmd = new SqlCommand("Select * from Region where Sid=@Sid", conn);
        cmd.Parameters.AddWithValue("@Sid", Sid);
        cmd.ExecuteNonQuery();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        adp.Fill(ds);
        conn.Close();
        List CityDetails = new List();
        foreach (DataRow DR in ds.Tables[0].Rows)
        {
            string Rid = DR["Rid"].ToString();
            string RegionName = DR[" RegionName"].ToString();
            CityDetails.Add(new CascadingDropDownNameValue(RegionName, Rid));
        }
        return CityDetails.ToArray();
    }

    
}
Posted
Updated 6-Mar-15 2:09am
v2
Comments
What is the exact issue and on which line? Have you debugged?
Joan Magnet 6-Mar-15 9:50am    
Web services use to have issues with non standard data types.

if this is the problem, try to serialize your object (xml for example), and send it as string.

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