Saturday, March 24, 2012

WCF AJAX Enabled Service and looping through Dictionary<string,string>

I hope someone can help me on this. I've tried every sample and cant seem to figure it out. I'm returning a Dictionary<string,string> from a WCF Service using Visual 2008 with .Net 3.5.

public Dictionary<string, string> RetrieveNavigationStylesLists()
{
Dicationary<string,string> data = null;

...

data = new Dictionary<string, string>();
data.Add("StyleID", styles[loop][0].ToString());
data.Add("Style", styles[loop][1].ToString());
data.Add("Default", styles[loop][2].ToString());

return data;

}

in my javascript i've tried the following:

...
// WCF Service is invoked an on success calls the function below

function onNavigationSuccess(args)
{
for(var data in args)
{
var key = data;
var keyValue = args[data];

}
}

But when i loop through the data i get only

loop 1:
key = 0
keyValue =
-key = "StyleID"
-value = "2"

loop 2:
key = 1
keyValue =
-key = "Style"
- value = "Page Title"

I cant seem to get the key name or the key value

If i look at args is contains the following data:

args = [0]
which has key="StyleID" and value="2"
[1]
which has key="Style" and value="Page Title"
[2]
which has key="Default" and value="False"

I've tried every sample that is available but cant seem to get it to work

Thanks




check this hope it helpshttp://wiki.freaks-unidos.net/javascript-libraries

No comments:

Post a Comment