I’m writing a .NET app that calls a WCF Data Service that requires authentication credentials to be passed in an HTTP header. I’m setting that header in a DataServiceContext.SendingRequest event handler. The service then returns an authentication token in a cookie. The client is expected to provide this cookie on subsequent calls. I can set cookies in the SendingRequest event, but I’ve been unable to find a way to hook the response in order to get the cookie in the first place. (Why isn’t there a DataServiceContext.ResponseReceived event?) Can anyone tell me either (1) how to hook the response so that I can read the HttpWebResponse.Cookies collection, or (2) how to configure the WCF Data Service client plumbing to handle cookies automatically?
Thanks for any insights or direction!
Dave
I can’t think of a way to do this through event handlers. But you can get to it through the OperationResponse. For example if you invoke the query by running Execute it returns an instance which derives from OperationResponse (http://msdn.microsoft.com/en-us/library/system.data.services.client.operationresponse.aspx). That exposes the response headers. This is also true for SaveChanges and so on.