Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my web service code is...
C#
[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 CasCadingDropDown : System.Web.Services.WebService
{
    //private DataSet ds = new DataSet();
    //private DataTable dt = new DataTable();
    public CasCadingDropDown()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    
    [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public CascadingDropDownNameValue[] GetStates(string knownCategoryValues, string category)
    {
        StringDictionary ck = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        string SomeOtherThing = "";
        if (!ck.ContainsKey("SomeOtherThing") || ck["SomeOtherThing"] == null)
        {
            SomeOtherThing = ck["SomeOtherThing"];
            
        }
        else
        {
            return null;
        }
     using(NpgsqlConnection conn=new NpgsqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
    {
      using(NpgsqlCommand cmd=new NpgsqlCommand("getstates",conn))
      {
        cmd.CommandType=CommandType.StoredProcedure;
        
        conn.Open();
        List<cascadingdropdownnamevalue> states = new List<cascadingdropdownnamevalue>();
            using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string StateId = (string)reader[0].ToString();
                        string StateName = (string)reader[1].ToString();
                        if(!string.IsNullOrEmpty(SomeOtherThing))
                        {
                            if(SomeOtherThing==StateId)
                        states.Add(new CascadingDropDownNameValue(StateName, Convert.ToString(StateId),true));
                        }
                        else
                        {
                             states.Add(new CascadingDropDownNameValue(StateName, Convert.ToString(StateId)));
                        }
                    }
                }
          return states.ToArray();
        
      }
        
     }
    }
 [WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public CascadingDropDownNameValue[] GetDistricts(string knownCategoryValues, string category)
    {

        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        int StateId;
        if (!kv.ContainsKey("States") || !Int32.TryParse(kv["States"], out StateId))
        {
            return null;
        }
        using (NpgsqlConnection conn = new NpgsqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
        {
            using (NpgsqlCommand cmd = new NpgsqlCommand("getdistricts", conn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new NpgsqlParameter("_stateid", StateId));
                // cmd.Parameters.Add(new NpgsqlParameter("_stateid",DbType.Int32,int.MaxValue,"stateid",ParameterDirection.Input,false,Byte.MaxValue,byte.MaxValue,DataRowVersion.Default,Formats.ConvertToInt(StateId)));
                //cmd.Parameters.Add("_stateid", StateId);
                conn.Open();
                List<cascadingdropdownnamevalue> districts = new List<cascadingdropdownnamevalue>();
                using (NpgsqlDataReader rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        string districtid = (string)rdr[0].ToString();
                        string districtName = (string)rdr[1].ToString();
                        districts.Add(new CascadingDropDownNameValue(districtName, districtid));
                    }
                }
                return districts.ToArray();
            }

        }
    }

states cascading dropdown works good. when i select state the district drop down filled with method error 500..i put the break point and see the execution flow the cursor goes to end after using (NpgsqlDataReader rdr = cmd.ExecuteReader())
Posted
v3
Comments
[no name] 9-Oct-15 8:40am    
Question :

When the error occurs? When selecting district dropdown or state dropdown?
Provide exception details what are you getting.
User-11630313 9-Oct-15 8:46am    
thank you for responding..when i select state drop down the district drop down filled with the error..Method Error 500
[no name] 9-Oct-15 8:48am    
Values are loaded into district dropdown?
User-11630313 9-Oct-15 8:50am    
not loading..just displaying Method error 500
[no name] 9-Oct-15 9:07am    
Please go through below URL:

http://www.codeproject.com/Questions/395904/how-to-solve-Web-Service-call-failed-error

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