private void HandleOperationResponseData(HttpWebResponse response, Stream responseStream) { Version version; Func <Stream> getResponseStream = null; Dictionary <string, string> headers = WebUtil.WrapResponseHeaders(response); Descriptor descriptor = base.ChangedEntries[base.entryIndex]; MaterializerEntry entry = null; Exception exception = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], () => responseStream, false, out version); if (((responseStream != null) && (descriptor.DescriptorKind == DescriptorKind.Entity)) && (exception == null)) { EntityDescriptor entityDescriptor = (EntityDescriptor)descriptor; if (((entityDescriptor.State == EntityStates.Added) || (entityDescriptor.StreamState == EntityStates.Added)) || ((entityDescriptor.State == EntityStates.Modified) || (entityDescriptor.StreamState == EntityStates.Modified))) { try { ResponseInfo responseInfo = base.CreateResponseInfo(entityDescriptor); if (getResponseStream == null) { getResponseStream = () => responseStream; } HttpWebResponseMessage message = new HttpWebResponseMessage(response, getResponseStream); entry = ODataReaderEntityMaterializer.ParseSingleEntityPayload(message, responseInfo, entityDescriptor.Entity.GetType()); entityDescriptor.TransientEntityDescriptor = entry.EntityDescriptor; } catch (Exception exception2) { exception = exception2; if (!CommonUtil.IsCatchableExceptionType(exception2)) { throw; } } } } this.cachedResponses.Add(new CachedResponse(descriptor, headers, response.StatusCode, version, (entry != null) ? entry.Entry : null, exception)); if (exception != null) { descriptor.SaveError = exception; } }
/// <summary> /// Handle the response payload. /// </summary> /// <param name="responseMsg">httpwebresponse instance.</param> /// <param name="responseStream">stream containing the response payload.</param> private void HandleOperationResponseData(IODataResponseMessage responseMsg, Stream responseStream) { Debug.Assert(this.entryIndex >= 0 && this.entryIndex < this.ChangedEntries.Count, string.Format(System.Globalization.CultureInfo.InvariantCulture, "this.entryIndex = '{0}', this.ChangedEntries.Count() = '{1}'", this.entryIndex, this.ChangedEntries.Count)); // Parse the response Descriptor current = this.ChangedEntries[this.entryIndex]; MaterializerEntry entry = default(MaterializerEntry); Version responseVersion; Exception exception = BaseSaveResult.HandleResponse(this.RequestInfo, (HttpStatusCode)responseMsg.StatusCode, responseMsg.GetHeader(XmlConstants.HttpODataVersion), () => { return(responseStream); }, false /*throwOnFailure*/, out responseVersion); var headers = new HeaderCollection(responseMsg); if (responseStream != null && current.DescriptorKind == DescriptorKind.Entity && exception == null) { // Only process the response if the current resource is an entity and it's an insert or update scenario EntityDescriptor entityDescriptor = (EntityDescriptor)current; // We were ignoring the payload for non-insert and non-update scenarios. We need to keep doing that. if (entityDescriptor.State == EntityStates.Added || entityDescriptor.StreamState == EntityStates.Added || entityDescriptor.State == EntityStates.Modified || entityDescriptor.StreamState == EntityStates.Modified) { try { ResponseInfo responseInfo = this.CreateResponseInfo(entityDescriptor); var responseMessageWrapper = new HttpWebResponseMessage( headers, responseMsg.StatusCode, () => responseStream); entry = ODataReaderEntityMaterializer.ParseSingleEntityPayload(responseMessageWrapper, responseInfo, entityDescriptor.Entity.GetType()); entityDescriptor.TransientEntityDescriptor = entry.EntityDescriptor; } catch (Exception ex) { exception = ex; if (!CommonUtil.IsCatchableExceptionType(ex)) { throw; } } } } this.cachedResponses.Add(new CachedResponse( current, headers, (HttpStatusCode)responseMsg.StatusCode, responseVersion, entry, exception)); if (exception != null) { current.SaveError = exception; // DEVNOTE(pqian): // There are two possible scenario here: // 1. We are in the sync code path, and there's an in stream error on the server side, or there are bad xml thrown // 2. We are in the async code path, there's a error thrown on the server side (any error) // Ideally, we need to check whether we want to continue to the next changeset. (Call this.CheckContinueOnError) // However, in V1/V2, we did not do this. Thus we will always continue on error on these scenarios } }