Question

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?

Was it helpful?

Solution

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.

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

In ODataLib the ETag is exposed through ODataEntry.ETag.

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:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top