.net - WebMethod 响应格式

标签 .net web-services json asmx

我最近看到一个 jQuery 示例,其中对“Default.aspx/Test”进行了 POST,其中 Test 是 Default.aspx 中的 WebMethod,请求的内容类型是“application/json”。

WebMethod 的回复是 JSON 格式的。我一直认为 WebMethods 返回 SOAP 响应,但如果我正确解释了这段代码,就像我说的那样,WebMethod 返回 JSON。

它是否正确? WebMethods 是否以请求内容类型的格式返回响应?从什么时候开始可以做到这一点?总是?或者这是因为我安装了 ASP.NET AJAX?如果是这样,我可以反汇编哪些 namespace 以查看其工作原理?

我只使用 WebMethods 进行 .NET 到 .NET 的通信,它一直在 SOAP 中,并且始终编写自定义代码以根据指定所需的请求查询字符串参数以正确的格式(SOAP、JSON 或 XML)响应格式。我一直认为这种元格式功能需要 WCF。

最佳答案

它是 ASP.NET AJAX 的一部分.参见示例 Using Web Services in ASP.NET AJAX .
AJAX 客户端架构的一部分如下所示:

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.

关于.net - WebMethod 响应格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/625250/

相关文章:

javascript - 使用 Axios 将表单数据发布到 .NET API

php - 拍摄相机照片并将其发送到 iPhone 中的 php 服务器

json - 在grafana中使用正则表达式从字符串字段中提取值

Java EE 6 - 作为有状态 session bean 的有状态 REST

web-services - 使用Delphi 2007将Base64字符串作为二进制文件保存到磁盘

ios - Objective-c 中的 NSTaggedPointerString objectForKey

.net - 使用 JSON 将日期传递到 .NET

.net - 即使浏览器站点关闭,Log4net 文件也会被锁定

c# - 检查 Task.Factory.StartNew 何时完成?

.net - .NET 业务层中的结构与类