views:

39

answers:

1

ASP.NET [WebMethod] does it always return XML?

I know it can only return serializable data types.

+5  A: 

As I'm aware of, you can return XML or JSON.

To return JSON add this annotation or your method:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

And on your class allow ScriptService

[ScriptService]

An example:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Dictionary<string, object> Test()
{
    var ret = new Dictionary<string, object>();
    ret.Add("Test", 1);
    return ret;
}

// result:
{d:{Test:1}}
BrunoLM