WebMethod响应格式 [英] WebMethod response format
问题描述
我最近看到了一个jQuery示例,其中对"Default.aspx/Test"进行了POST,其中Test是Default.aspx中的WebMethod,而请求的内容类型为"application/json".>
WebMethod的回复是JSON.我一直以为WebMethods会返回SOAP响应,但是如果我正确解释了此代码(如我所说的那样),则WebMethod会返回JSON.
这是正确的吗? WebMethods是否以请求内容类型的格式返回响应?从什么时候开始有可能?总是?还是这是因为我安装了ASP.NET AJAX?如果是这样,我可以反汇编哪些名称空间以查看其工作原理?
我只使用了WebMethods for .NET到.NET的通信,该通信已使用SOAP,并且始终根据请求查询字符串参数以正确的格式(SOAP,JSON或XML)编写自定义代码以进行响应指定所需的格式.我一直以为WCF是这种元格式功能所必需的.
它是ASP.NET AJAX
的一部分.例如,请参见在ASP.NET AJAX中使用Web服务.
AJAX客户端体系结构的一部分是这样的:
使用HTTP POST动词调用Web服务. POST请求的正文包含浏览器发送到服务器的数据.它没有大小限制.因此,当数据大小超出GET请求的固有大小限制时,可以使用POST请求.客户端将请求序列化为 JSON 格式,并将其作为POST数据发送到服务器.服务器将 JSON 数据反序列化为.NET Framework类型,并进行实际的Web服务调用.在响应期间,服务器对返回值进行序列化,然后将它们传递回客户端,客户端将它们反序列化为JavaScript对象进行处理.
I recently saw a jQuery example where a POST was made to "Default.aspx/Test", where Test was a WebMethod in Default.aspx, and the content-type for the request was "application/json".
The reply from the WebMethod was in JSON. I always thought WebMethods returned SOAP responses, but if I'm interpreting this code correctly, like I said, the WebMethod returns JSON.
Is this correct? Do WebMethods return a response in the format of the request content-type? Since when has this been possible? Always? Or is this because I have ASP.NET AJAX installed? If so, what namespaces can I disassemble to see how this works?
I've only used WebMethods for .NET to .NET communication, which has been in SOAP, and always written custom code to respond in the correct format (SOAP, JSON, or XML), based on a request query string parameter specifying the desired format. I always thought WCF was required for this kind of metaformat functionality.
It is a part of ASP.NET AJAX
. See for example Using Web Services in ASP.NET AJAX.
Part of the AJAX client architecture goes like this:
Call Web services by using the HTTP POST verb. A POST request has a body that contains the data that the browser sends to the server. It does not have a size limitation. Therefore, you can use a POST request when the size of the data exceeds the intrinsic size limitation for a GET request. The client serializes the request into JSON format and sends it as POST data to the server. The server deserializes the JSON data into .NET Framework types and makes the actual Web service call. During the response, the server serializes the return values and passes them back to the client, which deserializes them into JavaScript objects for processing.
这篇关于WebMethod响应格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!