This is a migrated thread and some comments may be shown as answers.

Error Setting context Parameter for Web Service Call

7 Answers 258 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Shahryar Ali
Top achievements
Rank 1
Shahryar Ali asked on 16 Feb 2010, 10:43 PM

I have looked through the threads and the link provided for setting the 'context' parameter to pass to a web service, but I am not getting it to work.  I am sure it's something straightforward that I have missed.  For simplicity, I had the Javascript function simply load a literal value rather than the value of an existing page control.  When I click on the combo box, i get the error "Invalid web service call, missing value for parameter 'ctx' "  Here are the code snippets:

 

<telerik:RadComboBox ID="cboSMAList" runat="server" EmptyMessage="None" Width="230px" EnableLoadOnDemand="true" OnClientItemsRequesting="CurrentInvestorForSMA" >

 

 

<WebServiceSettings Path="~/ws/ADAdvisorMaintService.asmx" Method="SMAList" />

 

 

</telerik:RadComboBox>

 



 

function CurrentInvestorForSMA(sender, eventArgs) {

 

 

var context = eventArgs.get_context();

 

context[

"InvID"] = "2";

 

}

 


And here's the Web service piece:


[

WebMethod]

 

 

public RadComboBoxItemData[] SMAList(object ctx )

 

{

 

int invID = 0;

 

 

IDictionary<string, object> contextDictionary = (IDictionary<string, object>) ctx;

 

invID =

Convert.ToInt32(contextDictionary["InvID"]);

Thanks,
S.

 

7 Answers, 1 is accepted

Sort by
0
Matthew Dvorak
Top achievements
Rank 1
answered on 17 Feb 2010, 06:18 PM
I am also getting the same issue.

Using a tree control to select a point in a data hierarchy, then trying to call the web service based on the value of the node when checked. (Why checked and not just clicked? Part of the requirements.) You'll see that I'm not currently parsing out the actual node value, but faking the data to pass for now to just minimize the problem.

When I call the web service, it dies with [Message":"Invalid web service call, missing value for parameter: \u0027eventArgs\u0027."

Javascript handler for RadTreeView:
function OnTreeHierarchy_Checked(sender, eventArgs) {  
 
    var node = eventArgs.get_node();  
    var grid = $find(dataGridName);  
 
    var dataContainer = "{'RegionID':'1','LocationID':'1','AreaID':'8','SiloID':'null','DeptID':'null'}";  
 
    if (node.get_checked()) // Checked - add selection to panel.  
    {  
        $.ajax(  
            {  
                type: "POST",  
                url: "../WebServices/Hierarchy.asmx/GetDetails",  
                data: dataContainer,  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function(msg) { AddRow(node, msg); },  
                error: function(msg) { HandleError(node, msg); }  
            }  
        );  
    }  
    else // Unchecked - remove selection from grid.  
    {  
      
    }  
}  
 
function AddRow(node, response) {  
    // Code to add a new row to the grid.  
}  
 
function HandleError(node, response) {  
    // Code to handle when the web service fails.  

The web method (Other web methods are working just fine, just not the GetDetails method):
[WebMethod]  
        public BudgetSummaryRow GetDetails(object eventArgs)  
        {  
            var dictContext = (IDictionary<stringobject>)eventArgs;  
 
            int temp;  
 
            int? regionID = null;  
            int? locationID = null;  
            int? areaID = null;  
            int? siloID = null;  
            int? deptID = null;  
 
            if (int.TryParse((string)dictContext["RegionID"], out temp))  
                regionID = temp;  
 
            if (int.TryParse((string)dictContext["LocationID"], out temp))  
                locationID = temp;  
 
            if (int.TryParse((string)dictContext["AreaID"], out temp))  
                areaID = temp;  
 
            if (int.TryParse((string)dictContext["SiloID"], out temp))  
                siloID = temp;  
 
            if (int.TryParse((string)dictContext["DeptID"], out temp))  
                deptID = temp;  
 
            // At this point we need to call the (as yet non-existant) database to get the current row of data.  
 
            // But for now, just faking the data return.  
            BudgetSummaryRow newRow = new BudgetSummaryRow(Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm());  
 
            return newRow;  
        } 

BudgetSummaryRow class:
public class BudgetSummaryRow  
    {
        #region Constructors  
        /// <summary>  
        /// Creates a non-initialized BudgetSummaryRow object.  
        /// </summary>  
        public BudgetSummaryRow()  
        {  
        }  
 
        /// <summary>  
        /// Creates a pre-initialized BudgetSummaryRow object.  
        /// </summary>  
        /// <param name="m01">Value of Month 1</param>  
        /// <param name="m02">Value of Month 2</param>  
        /// <param name="m03">Value of Month 3</param>  
        /// <param name="m04">Value of Month 4</param>  
        /// <param name="m05">Value of Month 5</param>  
        /// <param name="m06">Value of Month 6</param>  
        /// <param name="m07">Value of Month 7</param>  
        /// <param name="m08">Value of Month 8</param>  
        /// <param name="m09">Value of Month 9</param>  
        /// <param name="m10">Value of Month 10</param>  
        /// <param name="m11">Value of Month 11</param>  
        /// <param name="m12">Value of Month 12</param>  
        public BudgetSummaryRow(int m01, int m02, int m03, int m04, int m05, int m06, int m07, int m08, int m09, int m10, int m11, int m12)  
        {  
            M01 = m01;  
            M02 = m02;  
            M03 = m03;  
            M04 = m04;  
            M05 = m05;  
            M06 = m06;  
            M07 = m07;  
            M08 = m08;  
            M09 = m09;  
            M10 = m10;  
            M11 = m11;  
            M12 = m12;  
        }
        #endregion Constructors  
 
        #region Properties  
        public int M01 { getset; }  
        public int M02 { getset; }  
        public int M03 { getset; }  
        public int M04 { getset; }  
        public int M05 { getset; }  
        public int M06 { getset; }  
        public int M07 { getset; }  
        public int M08 { getset; }  
        public int M09 { getset; }  
        public int M10 { getset; }  
        public int M11 { getset; }  
        public int M12 { getset; }  
        public string Attributes { getset; }
        #endregion Properties  
    } 

I'm probably missing something easy, anyone care to bash me with a clue stick?

Thanks!
0
Matthew Dvorak
Top achievements
Rank 1
answered on 17 Feb 2010, 07:22 PM
OK, I figured my issue out, unknown if it's the same problem as yours. My issue comes down to a lack of understanding of the "data:" parameter of the $.ajax call. I thought I had to pack the whole set of data into an object (eventArgs in the previous case), then tear the object back apart on the web service side to get the individual elements. That was wrong. It turns out that the name/value pairs in the data element are then matched to the names of the input parameters of the web service by jQuery, and a matching element name has to exist.

Here's the working code (Only the changes):

Updated Javascript handler:
function OnTreeHierarchy_Checked(sender, eventArgs) {  
 
    var node = eventArgs.get_node();  
    var grid = $find(dataGridName);  
 
    var dataContainer = "{'RegionID':'1','LocationID':'1','AreaID':'8','SiloID':'null','DeptID':'null'}";  
 
    if (node.get_checked()) // Checked - add selection to panel.  
    {  
        $.ajax(  
            {  
                type: "POST",  
                url: "../WebServices/Hierarchy.asmx/GetDetails",  
                data: dataContainer,  
                contentType: "application/json; charset=utf-8",  
                dataType: "json",  
                success: function(msg) { AddRow(node, msg); },  
                error: function(msg) { HandleError(node, msg); }  
            }  
        );  
    }  
    else // Unchecked - remove selection from grid.  
    {  
      
    }  
}  
 
function AddRow(node, response) {  
    // Code to add a new row to the grid.  
}  
 
function HandleError(node, response) {  
    // Code to handle when the web service fails.  

Updated web method:
[WebMethod]  
        public BudgetSummaryRow GetDetails(string RegionID, string LocationID, string AreaID, string SiloID, string DeptID)  
        {  
            int temp;  
 
            int? regionID = null;  
            int? locationID = null;  
            int? areaID = null;  
            int? siloID = null;  
            int? deptID = null;  
 
            if (int.TryParse(RegionID, out temp))  
                regionID = temp;  
 
            if (int.TryParse(LocationID, out temp))  
                locationID = temp;  
 
            if (int.TryParse(AreaID, out temp))  
                areaID = temp;  
 
            if (int.TryParse(SiloID, out temp))  
                siloID = temp;  
 
            if (int.TryParse(DeptID, out temp))  
                deptID = temp;  
 
            // At this point we need to call the (as yet non-existant) database proc to get the current row of data.  
 
            // But for now, just faking the data return.  
            BudgetSummaryRow newRow = new BudgetSummaryRow(Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm(), Rndm());  
 
            return newRow;  
        } 
0
Shahryar Ali
Top achievements
Rank 1
answered on 17 Feb 2010, 10:15 PM
Matthew,

I tried re-doing the javascript using your method (acutally constructing the Webservice call), but no luck. 

I still get exactly the same error : "Invalid web service call, missing value for parameter 'invID'."  The param name has changed because i took out the context object from my first script and replaced it with the actual parameter, as you had done.  Thanks for the contribution to the thread, every bit of light shed on the problem helps.

Shahryar

0
Matthew Dvorak
Top achievements
Rank 1
answered on 17 Feb 2010, 10:27 PM
Have you seen a best practice for using the getContext call you are using?  I don't think it's necessary, but don't know the backstory. Also, the context object seems to be an IDictionary, and pretty much anything implementing IDictionary seems to cause problems with web services, so I'd look at simplifying the call.

Do you need any of the data (besides the invID) that exists in the context?

I'd just tweak the web service to expect a parameter named "invID" (and any additional params you might need) as a single string param, then convert it to an int inside the web service method. (Just makes things a lot easier in a lot of cases.)

Change your data string to resemble "{'invID':'2'}" and then jQuery will handle matching the param name to the web method param named "invID".
0
Shahryar Ali
Top achievements
Rank 1
answered on 17 Feb 2010, 10:37 PM
Matthew,

Even though I don't show the entire code pieces, I actually did change the signature of the Web method to 'string invID', and formed the data string as you suggested.  This did not work, giving the error I described in the earlier post.  This is strange, since I don't see anything different as between our code samples.  The javascript is obviously firing, since the error complains about the lack of an argument to the Web service parameter.  Any other ideas are welcome.

Thanks,
Shahryar
0
Simon
Telerik team
answered on 18 Feb 2010, 05:30 PM
Hi Shahryar Ali,

Please try modifying your Web Method signature to accept a parameter of type RadComboBoxContext (as shown in this demo). Does this help?

Kind regards,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Shahryar Ali
Top achievements
Rank 1
answered on 18 Feb 2010, 06:14 PM
Simon,

Well, it now works.  However, changing the parameter type to RadComboBoxContext was not the fix - it works even if the type is specified as 'object' as well. 

What DID work was to change the parameter name to 'context' instead of 'ctx' in the web service argument list.  I'm not sure I understand why the parameter name should matter, but it now works. 

If you can discover an explanation for this, I'm sure others would be curious to know as well.

Thanks for your help,
Shahryar
Tags
ComboBox
Asked by
Shahryar Ali
Top achievements
Rank 1
Answers by
Matthew Dvorak
Top achievements
Rank 1
Shahryar Ali
Top achievements
Rank 1
Simon
Telerik team
Share this question
or