예제 #1
0
        protected override void CompletedRequest()
        {
            Func <Stream> getResponseStream = null;

            if (this.response != null)
            {
                InvalidOperationException e = null;
                if (!WebUtil.SuccessStatusCode(this.response.StatusCode))
                {
                    getResponseStream = () => WebUtil.GetResponseStream(this.response, (DataServiceContext)base.Source);

                    e = BaseSaveResult.GetResponseText(getResponseStream, this.response.StatusCode);
                }
                if (e != null)
                {
                    this.response.Close();
                    base.HandleFailure(e);
                }
            }
        }
예제 #2
0
        private DataServiceResponse HandleBatchResponse()
        {
            Func <Stream>       func2             = null;
            Func <Stream>       getResponseStream = null;
            DataServiceResponse response3;
            bool flag = true;

            try
            {
                Version          version;
                ODataBatchReader reader;
                if ((base.batchResponse == null) || (base.batchResponse.StatusCode == HttpStatusCode.NoContent))
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_ExpectedResponse(1));
                }
                if (func2 == null)
                {
                    func2 = () => this.ResponseStream;
                }
                Func <Stream> func = func2;
                BaseSaveResult.HandleResponse(base.RequestInfo, base.batchResponse.StatusCode, base.batchResponse.Headers["DataServiceVersion"], func, true, out version);
                if (this.ResponseStream == null)
                {
                    System.Data.Services.Client.Error.ThrowBatchExpectedResponse(InternalError.NullResponseStream);
                }
                HttpWebResponseMessage     responseMessage = new HttpWebResponseMessage(base.batchResponse, func);
                ODataMessageReaderSettings settings        = WebUtil.CreateODataMessageReaderSettings(base.RequestInfo.GetDeserializationInfo(null), null, false);
                this.batchMessageReader = new ODataMessageReader(responseMessage, settings);
                try
                {
                    reader = this.batchMessageReader.CreateODataBatchReader();
                }
                catch (Exception responseText)
                {
                    string   str;
                    Encoding encoding;
                    HttpProcessUtility.ReadContentType(base.batchResponse.ContentType, out str, out encoding);
                    if (string.Equals("text/plain", str))
                    {
                        if (getResponseStream == null)
                        {
                            getResponseStream = () => WebUtil.GetResponseStream(base.batchResponse, (DataServiceContext)base.Source);
                        }
                        responseText = BaseSaveResult.GetResponseText(getResponseStream, base.batchResponse.StatusCode);
                    }
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_ExpectedContentType(base.batchResponse.ContentType), responseText);
                }
                DataServiceResponse response = this.HandleBatchResponseInternal(reader);
                flag      = false;
                response3 = response;
            }
            catch (DataServiceRequestException)
            {
                throw;
            }
            catch (InvalidOperationException exception3)
            {
                Dictionary <string, string> headers = WebUtil.WrapResponseHeaders(base.batchResponse);
                int statusCode = (base.batchResponse == null) ? 500 : ((int)base.batchResponse.StatusCode);
                DataServiceResponse response2 = new DataServiceResponse(headers, statusCode, null, this.IsBatch);
                throw new DataServiceRequestException(System.Data.Services.Client.Strings.DataServiceException_GeneralError, exception3, response2);
            }
            finally
            {
                if (flag)
                {
                    Util.Dispose <ODataMessageReader>(ref this.batchMessageReader);
                }
            }
            return(response3);
        }