开发者

Does asp.net webmethod always return jsonified data?

开发者 https://www.devze.com 2023-01-07 17:13 出处:网络
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 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

精彩评论

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

关注公众号