开发者

Does asp.net webmethod always return jsonified data?

I have general question that if an asp.net webmethod always returns d开发者_JS百科ata in 'json' form.If not what is the default return datatype of a webmethod?

I am wondering if there is a way I can get the data from a webmethod in 'HTML' rather than 'json'?

Thanks


PageMethods are a part of the ASP.NET AJAX Framework (ScriptManager).

By default, ASP.NET AJAX uses JSON as opposed to SOAP.

This is by design, mainly because the ASP.NET AJAX Javascript library it optimized to work with JSON objects.

You can override this default by specifying the [ResponseFormat] attribute on the web method.

Like this:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XmlElement GetFoo(string url)
{

Here is a decent article on PageMethods and ASP.NET AJAX-enabled web services.


The return type for a default webservice should SOAP (an XML Format), for WCF there is a REST pack which can change it return type to JSON

[http://msdn.microsoft.com/en-us/netframework/cc950529.aspx][1]

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜