예제 #1
0
        /// <summary>
        /// Reads the response with error handling
        /// </summary>
        /// <param name="response">The response.</param>
        /// <returns>Service response.</returns>
        private object ReadResponse(IEwsHttpWebResponse response)
        {
            object serviceResponse;

            try
            {
                this.Service.ProcessHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, response);

                // If tracing is enabled, we read the entire response into a MemoryStream so that we
                // can pass it along to the ITraceListener. Then we parse the response from the
                // MemoryStream.
                if (this.Service.IsTraceEnabledFor(TraceFlags.EwsResponse))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        using (Stream serviceResponseStream = ServiceRequestBase.GetResponseStream(response))
                        {
                            // Copy response to in-memory stream and reset position to start.
                            EwsUtilities.CopyStream(serviceResponseStream, memoryStream);
                            memoryStream.Position = 0;
                        }

                        this.TraceResponseXml(response, memoryStream);

                        serviceResponse = this.ReadResponseXml(memoryStream, response.Headers);
                    }
                }
                else
                {
                    using (Stream responseStream = ServiceRequestBase.GetResponseStream(response))
                    {
                        serviceResponse = this.ReadResponseXml(responseStream, response.Headers);
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    IEwsHttpWebResponse exceptionResponse = this.Service.HttpWebRequestFactory.CreateExceptionResponse(e);
                    this.Service.ProcessHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, exceptionResponse);
                }

                throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, e.Message), e);
            }
            catch (IOException e)
            {
                // Wrap exception.
                throw new ServiceRequestException(string.Format(Strings.ServiceRequestFailed, e.Message), e);
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                }
            }

            return(serviceResponse);
        }
예제 #2
0
 /// <summary>
 /// Validates this view.
 /// </summary>
 /// <param name="request">The request using this view.</param>
 internal virtual void InternalValidate(ServiceRequestBase request)
 {
     if (this.PropertySet != null)
     {
         this.PropertySet.InternalValidate();
         this.PropertySet.ValidateForRequest(request, true /*summaryPropertiesOnly*/);
     }
 }
예제 #3
0
 /// <summary>
 /// Validates this view.
 /// </summary>
 /// <param name="request">The request using this view.</param>
 internal virtual void InternalValidate(ServiceRequestBase request)
 {
     if (this.PropertySet != null)
     {
         this.PropertySet.InternalValidate();
         this.PropertySet.ValidateForRequest(request, true /*summaryPropertiesOnly*/);
     }
 }
예제 #4
0
        /// <summary>
        /// Validate instance.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            if (this.endDate < this.StartDate)
            {
                throw new ServiceValidationException(Strings.EndDateMustBeGreaterThanStartDate);
            }
        }
        /// <summary>
        /// Validates this view.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            if (this.Traversal.HasValue)
            {
                EwsUtilities.ValidateEnumVersionValue(this.traversal, request.Service.RequestedServerVersion);
            }

            if (this.ViewFilter.HasValue)
            {
                EwsUtilities.ValidateEnumVersionValue(this.viewFilter, request.Service.RequestedServerVersion);
            }
        }
        /// <summary>
        /// Validates this view.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            if (this.Traversal.HasValue)
            {
                EwsUtilities.ValidateEnumVersionValue(this.traversal, request.Service.RequestedServerVersion);
            }

            if (this.ViewFilter.HasValue)
            {
                EwsUtilities.ValidateEnumVersionValue(this.viewFilter, request.Service.RequestedServerVersion);
            }
        }
        /// <summary>
        /// Contructor
        /// </summary>
        /// <param name="serviceRequest"></param>
        /// <param name="webRequest"></param>
        /// <param name="webAsyncResult"></param>
        /// <param name="asyncState"></param>
        public AsyncRequestResult(
            ServiceRequestBase serviceRequest,
            IEwsHttpWebRequest webRequest,
            IAsyncResult webAsyncResult,
            object asyncState)
        {
            EwsUtilities.ValidateParam(serviceRequest, "serviceRequest");
            EwsUtilities.ValidateParam(webRequest, "webRequest");
            EwsUtilities.ValidateParam(webAsyncResult, "webAsyncResult");

            this.ServiceRequest = serviceRequest;
            this.WebAsyncResult = webAsyncResult;
            this.WebRequest     = webRequest;
            this.AsyncState     = asyncState;
        }
        /// <summary>
        /// Contructor
        /// </summary>
        /// <param name="serviceRequest"></param>
        /// <param name="webRequest"></param>
        /// <param name="asyncCallback"></param>
        /// <param name="asyncState"></param>
        public WebAsyncCallStateAnchor(
            ServiceRequestBase serviceRequest,
            IEwsHttpWebRequest webRequest,
            AsyncCallback asyncCallback,
            object asyncState)
        {
            EwsUtilities.ValidateParam(serviceRequest, "serviceRequest");
            EwsUtilities.ValidateParam(webRequest, "webRequest");

            this.ServiceRequest = serviceRequest;
            this.WebRequest     = webRequest;

            this.AsyncCallback = asyncCallback;
            this.AsyncState    = asyncState;
        }
예제 #9
0
        /// <summary>
        /// Processes the web exception.
        /// </summary>
        /// <param name="webException">The web exception.</param>
        private void ProcessWebException(WebException webException)
        {
            if (webException.Response != null)
            {
                IEwsHttpWebResponse httpWebResponse  = this.Service.HttpWebRequestFactory.CreateExceptionResponse(webException);
                SoapFaultDetails    soapFaultDetails = null;

                if (httpWebResponse.StatusCode == HttpStatusCode.InternalServerError)
                {
                    this.Service.ProcessHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, httpWebResponse);

                    // If tracing is enabled, we read the entire response into a MemoryStream so that we
                    // can pass it along to the ITraceListener. Then we parse the response from the
                    // MemoryStream.
                    if (this.Service.IsTraceEnabledFor(TraceFlags.EwsResponse))
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            using (Stream serviceResponseStream = ServiceRequestBase.GetResponseStream(httpWebResponse))
                            {
                                // Copy response to in-memory stream and reset position to start.
                                EwsUtilities.CopyStream(serviceResponseStream, memoryStream);
                                memoryStream.Position = 0;
                            }

                            this.TraceResponseXml(httpWebResponse, memoryStream);

                            EwsServiceXmlReader reader = new EwsServiceXmlReader(memoryStream, this.Service);
                            soapFaultDetails = this.ReadSoapFault(reader);
                        }
                    }
                    else
                    {
                        using (Stream stream = ServiceRequestBase.GetResponseStream(httpWebResponse))
                        {
                            EwsServiceXmlReader reader = new EwsServiceXmlReader(stream, this.Service);
                            soapFaultDetails = this.ReadSoapFault(reader);
                        }
                    }

                    if (soapFaultDetails != null)
                    {
                        switch (soapFaultDetails.ResponseCode)
                        {
                        case ServiceError.ErrorInvalidServerVersion:
                            throw new ServiceVersionException(Strings.ServerVersionNotSupported);

                        case ServiceError.ErrorSchemaValidation:
                            // If we're talking to an E12 server (8.00.xxxx.xxx), a schema validation error is the same as a version mismatch error.
                            // (Which only will happen if we send a request that's not valid for E12).
                            if ((this.Service.ServerInfo != null) &&
                                (this.Service.ServerInfo.MajorVersion == 8) && (this.Service.ServerInfo.MinorVersion == 0))
                            {
                                throw new ServiceVersionException(Strings.ServerVersionNotSupported);
                            }

                            break;

                        case ServiceError.ErrorIncorrectSchemaVersion:
                            // This shouldn't happen. It indicates that a request wasn't valid for the version that was specified.
                            EwsUtilities.Assert(
                                false,
                                "ServiceRequestBase.ProcessWebException",
                                "Exchange server supports requested version but request was invalid for that version");
                            break;

                        case ServiceError.ErrorServerBusy:
                            throw new ServerBusyException(new ServiceResponse(soapFaultDetails));

                        default:
                            // Other error codes will be reported as remote error
                            break;
                        }

                        // General fall-through case: throw a ServiceResponseException
                        throw new ServiceResponseException(new ServiceResponse(soapFaultDetails));
                    }
                }
                else
                {
                    this.Service.ProcessHttpErrorResponse(httpWebResponse, webException);
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Validates this property set instance for request to ensure that:
        /// 1. Properties are valid for the request server version.
        /// 2. If only summary properties are legal for this request (e.g. FindItem) then only summary properties were specified.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="summaryPropertiesOnly">if set to <c>true</c> then only summary properties are allowed.</param>
        internal void ValidateForRequest(ServiceRequestBase request, bool summaryPropertiesOnly)
        {
            foreach (PropertyDefinitionBase propDefBase in this.additionalProperties)
            {
                PropertyDefinition propertyDefinition = propDefBase as PropertyDefinition;
                if (propertyDefinition != null)
                {
                    if (propertyDefinition.Version > request.Service.RequestedServerVersion)
                    {
                        throw new ServiceVersionException(
                                  string.Format(
                                      Strings.PropertyIncompatibleWithRequestVersion,
                                      propertyDefinition.Name,
                                      propertyDefinition.Version));
                    }

                    if (summaryPropertiesOnly && !propertyDefinition.HasFlag(PropertyDefinitionFlags.CanFind, request.Service.RequestedServerVersion))
                    {
                        throw new ServiceValidationException(
                                  string.Format(
                                      Strings.NonSummaryPropertyCannotBeUsed,
                                      propertyDefinition.Name,
                                      request.GetXmlElementName()));
                    }
                }
            }

            if (this.FilterHtmlContent.HasValue)
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2010)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "FilterHtmlContent",
                                  ExchangeVersion.Exchange2010));
                }
            }

            if (this.ConvertHtmlCodePageToUTF8.HasValue)
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2010_SP1)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "ConvertHtmlCodePageToUTF8",
                                  ExchangeVersion.Exchange2010_SP1));
                }
            }

            if (!string.IsNullOrEmpty(this.InlineImageUrlTemplate))
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2013)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "InlineImageUrlTemplate",
                                  ExchangeVersion.Exchange2013));
                }
            }

            if (this.BlockExternalImages.HasValue)
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2013)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "BlockExternalImages",
                                  ExchangeVersion.Exchange2013));
                }
            }

            if (this.AddBlankTargetToLinks.HasValue)
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2013)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "AddTargetToLinks",
                                  ExchangeVersion.Exchange2013));
                }
            }

            if (this.MaximumBodySize.HasValue)
            {
                if (request.Service.RequestedServerVersion < ExchangeVersion.Exchange2013)
                {
                    throw new ServiceVersionException(
                              string.Format(
                                  Strings.PropertyIncompatibleWithRequestVersion,
                                  "MaximumBodySize",
                                  ExchangeVersion.Exchange2013));
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Validates this view.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            EwsUtilities.ValidateEnumVersionValue(this.traversal, request.Service.RequestedServerVersion);
        }
예제 #12
0
 /// <summary>
 /// Validates this view.
 /// </summary>
 /// <param name="request">The request using this view.</param>
 internal override void InternalValidate(ServiceRequestBase request)
 {
     base.InternalValidate(request);
 }
        /// <summary>
        /// Validate instance.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            if (this.endDate < this.StartDate)
            {
                throw new ServiceValidationException(Strings.EndDateMustBeGreaterThanStartDate);
            }
        }
 /// <summary>
 /// Validates this view.
 /// </summary>
 /// <param name="request">The request using this view.</param>
 internal override void InternalValidate(ServiceRequestBase request)
 {
     base.InternalValidate(request);
 }
예제 #15
0
        /// <summary>
        /// Validates this view.
        /// </summary>
        /// <param name="request">The request using this view.</param>
        internal override void InternalValidate(ServiceRequestBase request)
        {
            base.InternalValidate(request);

            EwsUtilities.ValidateEnumVersionValue(this.traversal, request.Service.RequestedServerVersion);
        }