Question

I've have a c# cascadingdropdown which works perfectly in debug locally and in debug mode on the live server, but I get [Method Error 500] in both drop downs when I view the page live through a browser. If I click the first drop down [Method Error 500] that then populates the second dropdown with [Method Error 500].

Here's the ASPX code:

<asp:DdlNoEventValidation ID="ddlWasteTypeList" runat="server" />
<asp:DdlNoEventValidation ID="ddlBinTypeList" runat="server" />

<asp:CustomValidator 
    ID="CustomValidator1" runat="server" 
    ControlToValidate="ddlBinTypeList"  
    OnServerValidate="CustomValidatorBinType_ServerValidate"
    ValidateEmptyText="True"
    >
</asp:CustomValidator>

<asp:CascadingDropDown ID="ccd1" runat="server"
    ServicePath="WasteDropDown.asmx"
    ServiceMethod="GetWaste"
    TargetControlID="ddlWasteTypeList"
    Category="Waste"
    PromptText="select waste" LoadingText="[Loading waste...]"
/>
<asp:CascadingDropDown ID="ccd2" runat="server"
    ServicePath="WasteDropDown.asmx"
    ServiceMethod="GetBinType"
    TargetControlID="ddlBinTypeList"
    ParentControlID="ddlWasteTypeList"
    Category="BinType"
    PromptText="select bin" LoadingText="[Loading bins...]"
/>

Here's the asmx code behind:

[ScriptService]
public class WasteDropDown : System.Web.Services.WebService 
{
    [WebMethod]
    public CascadingDropDownNameValue[] GetBinType(string knownCategoryValues, string category)
    {
        int wtID;
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        if (!kv.ContainsKey("Waste") || !Int32.TryParse(kv["Waste"], out wtID))
        {
            throw new ArgumentException("Couldn't find waste type.");
        };

        SqlConnection conn = new SqlConnection(myConn.conn);
        conn.Open();
        SqlCommand comm;
        comm = new SqlCommand("dbo.sl_TLU", conn);
        comm.CommandType = CommandType.StoredProcedure;
        comm.Parameters.Add(new SqlParameter("@binWTID", SqlDbType.Int));
        comm.Parameters["@binWTID"].Value = wtID;

        SqlDataReader dr = comm.ExecuteReader();
        List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

        while (dr.Read())
        {
            l.Add(new CascadingDropDownNameValue(
            dr["bT"].ToString(),
            dr["bPLUID"].ToString()));
        }
        conn.Close();
        return l.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetWaste(string knownCategoryValues, string category)
    {
        SqlConnection conn = new SqlConnection(myConn.conn);
        conn.Open();

        SqlCommand comm;
        comm = new SqlCommand("dbo.sl_binQWT", conn);
        comm.CommandType = CommandType.StoredProcedure;

        SqlDataReader dr = comm.ExecuteReader();
        List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

        while (dr.Read())
        {
            l.Add(new CascadingDropDownNameValue(
            dr["binWT"].ToString(),
            dr["wtID"].ToString()));
        }
        conn.Close();
        return l.ToArray();
    }
}

There's no ASP.Net errors in the logs. However, I have a similar ccd running on the same server on a different website and that works perfectly - very frustrating.

I did have a look at this Stackoverflow question, but to be honest I didn't quite get what the solution was - although I don't seem to have any duplicate dlls in the bin folder. I really think the issue is around here somewhere though.

I've double checked the SQL queries and they both return data.

Any suggestions? I've run out of them!

EDIT:

I've set up Failed Request Tracing and get this really helpful result:

MODULE_SET_RESPONSE_ERROR_STATUS Warning ModuleName="ManagedPipelineHandler", Notification="MAP_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo=""Warning

The same error was generated for /wastedropdown.asmx/getwaste and wastedropdown.asmx/getbintype

Hopefully this will mean something to someone!

EDIT2:

The code definitely works fine on a different website on the same server. I've got Fiddler out at get the following error:

{"Message":"An attempt was made to call the method \u0027GetWaste\u0027 using a GET request, which is not allowed.","StackTrace":" at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

HELP!

Was it helpful?

Solution 3

I found the answer which was down to using camel case method names which then conflicted with some IIS rewrite code to ensure urls were in lower case.

This was discovered by using Fiddler, which to my shame, had never used before. I'm now a total convert!

OTHER TIPS

I think it is because the data you are getting is too big. You have to add the following code into your web.config:

<system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="5000000" />
         </webServices>
     </scripting>
</system.web.extensions>

Regards


The method 500 I found is just due to incorrect code or database security permissions being set correctly.

So,ensure your data tables are returning data (e.g. does IIS apppool have correct permissions and make sure your KnownCategoryvalues(e.g. a value for bPLUID) and category(e.g. Bintype) are correct and the right way round in dr["bT"].ToString(), and r["bPLUID"].ToString()));. Check both web methods.

You can test the web methods by invocation. Get waste should not need values. getBinWaste probably will Known category value =bPLUID: [enter a id value here] category bintype.

exasperating but does work eventually.

I had same issue. Tt worked then stopped after I install additional role services. Then after scatched my head for several hours, I found out that in the site's Handler Mappings, one script method for *.asmx has wrong version number! look for public token: B03F5F7F11D50A3A, if you see version 2.0.0.0, then delete it. That's it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top