如何将 JSON 响应数据减少到最少
我通过以下方式创建了 WCF REST 服务:
[WebGet(UriTemplate = "StoreData/sid={SessionID}&Data={UserData}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
public string StoreData(string SessionID, string UserData)
{
string result = DBWorks.StoreUserData(SessionID, UserData);
return result;
}
该服务由移动设备使用,因此为了降低链接成本,我希望发送尽可能少的数据。上面的服务返回以下内容:
.CONNECT
.HTTP/1.1 200 OK
.Content-Length: 4
.Content-Type: application/json; charset=utf-8
.Server: Microsoft-HTTPAPI/2.0
.Date: Mon, 17 Oct 2011 23:25:55 GMT
.
."69"
上面示例中移动设备的唯一相关信息是 69。是否可以修改服务,使得示例中的任何其他数据都不会被发送?
谢谢你!
I Created WCF REST Service the following way:
[WebGet(UriTemplate = "StoreData/sid={SessionID}&Data={UserData}", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
public string StoreData(string SessionID, string UserData)
{
string result = DBWorks.StoreUserData(SessionID, UserData);
return result;
}
The service is consumed by mobile device so in order to reduce the link cost I would like to sent as little data as possible. The service above returns the following:
.CONNECT
.HTTP/1.1 200 OK
.Content-Length: 4
.Content-Type: application/json; charset=utf-8
.Server: Microsoft-HTTPAPI/2.0
.Date: Mon, 17 Oct 2011 23:25:55 GMT
.
."69"
The only relevant information from the axample above for mobile device is 69. Is it possible to modify the service such that any of other data from the example would not be sent?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于除了
69
之外的所有内容都是 HTTP 标头,因此我几乎看不出如何进一步融合它。Since everything besides the
69
are the HTTP headers, I hardly see how this could be melted down further.其他行是标准 HTTP 响应标头(日期和服务器除外)。即使您可以删除它们,您也不应该删除它们,否则您的客户端如何知道请求是否已成功处理(200 OK)或未成功处理(例如 400 Bad Request)?
The other lines are standard HTTP response headers (except maybe Date and Server). Even if you could remove them, you shouldn't otherwise how will your client know whether the request was processed succesfully (200 OK), or not (e.g. 400 Bad Request)?