如何从WCF数据服务响应中提取ETAG? [英] How do I extract ETAG from a WCF Dataservices response?

查看:73
本文介绍了如何从WCF数据服务响应中提取ETAG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在努力寻求该问题的答案.由于WCF数据服务不是线程安全的,并且经常需要重新创建它,因此,一旦我查询数据存储区中的记录,如何从该响应中提取ETAG,以便在重建数据上下文时可以使用它?

I've been trying to get an answer to this question for quite some time. Since the WCF Dataservice isn't thread safe, and often it needs to be recreated, once I query my datastore for a record, how do I extract the ETAG from that response so I can use it when I reconstruct my datacontext?

推荐答案

这取决于您在客户端上使用的语言/库以及在线使用的格式(ATOM与JSON). ETag存储在有效负载中,在单个实体有效负载的情况下,也存储在HTTP标头中. 一些库会为您提取它并为您提供直接访问权限(例如ODataLib或WCF Data Services客户端).如果您要自己解析有效负载,则需要自己提取它.

That depends on which language/library you're using on the client and which format you're using on the wire (ATOM vs JSON). The ETag is stored in the payload and in case of a single entity payload also in the HTTP headers. Some libraries extract it for you and give you direct access (for example ODataLib or WCF Data Services client). If you're parsing the payload yourself you would need to extract it yourself.

在WCF数据服务客户端中,可以通过DataServiceContext.GetEntityDescriptor(entity).ETag访问ETag.

In WCF Data Services client the ETag can be accessed through DataServiceContext.GetEntityDescriptor(entity).ETag.

在ODataLib中,ETag通过ODataEntry.ETag公开.

In ODataLib the ETag is exposed through ODataEntry.ETag.

在ATOM的有效负载中,ETag作为属性存储在名为m:etag的atom:entry元素上(m是元数据名称空间)

In the payload in ATOM ETag is stored as an attribute on the atom:entry element called m:etag (m is the metadata namespace) as described here:

详细JSON ETag中的有效内容存储为条目元数据的一部分.因此,在入口对象中有一个属性__metadata,该值是一个具有名为etag的属性的对象.参见第4.1.1章

In the payload in Verbose JSON ETag is stored as part of the entry metadata. So in the entry object there's a property __metadata which value is an object which has a property called etag. See chapter 4.1.1

这篇关于如何从WCF数据服务响应中提取ETAG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆