/// <summary>
        /// Traces a JSON request. This should only be used for synchronous requests, or synchronous situations
        /// (such as a WebException on an asynchrounous request).
        /// </summary>
        /// <param name="requestObject">The JSON request object.</param>
        protected void TraceJsonRequest(JsonObject requestObject)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                requestObject.SerializeToJson(memoryStream, this.Service.TraceEnablePrettyPrinting);

                memoryStream.Position = 0;

                using (StreamReader reader = new StreamReader(memoryStream))
                {
                    this.Service.TraceMessage(TraceFlags.EwsRequest, reader.ReadToEnd());
                }
            }
        }
        /// <summary>
        /// Traces the and emits the request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="needSignature"></param>
        /// <param name="needTrace"></param>
        private void TraceAndEmitRequest(IEwsHttpWebRequest request, bool needSignature, bool needTrace)
        {
            if (this.service.RenderingMethod == ExchangeService.RenderingMode.Xml)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (EwsServiceXmlWriter writer = new EwsServiceXmlWriter(this.Service, memoryStream))
                    {
                        writer.RequireWSSecurityUtilityNamespace = needSignature;
                        this.WriteToXml(writer);
                    }

                    if (needSignature)
                    {
                        this.service.Credentials.Sign(memoryStream);
                    }

                    if (needTrace)
                    {
                        this.TraceXmlRequest(memoryStream);
                    }

                    using (Stream serviceRequestStream = this.GetWebRequestStream(request))
                    {
                        EwsUtilities.CopyStream(memoryStream, serviceRequestStream);
                    }
                }
            }
            else if (this.service.RenderingMethod == ExchangeService.RenderingMode.JSON)
            {
                JsonObject requestObject = this.CreateJsonRequest();

                this.TraceJsonRequest(requestObject);

                using (Stream serviceRequestStream = this.GetWebRequestStream(request))
                {
                    requestObject.SerializeToJson(serviceRequestStream);
                }
            }
        }
        /// <summary>
        /// Emits the request.
        /// </summary>
        /// <param name="request">The request.</param>
        private void EmitRequest(IEwsHttpWebRequest request)
        {
            if (this.Service.RenderingMethod == ExchangeService.RenderingMode.Xml)
            {
                using (Stream requestStream = this.GetWebRequestStream(request))
                {
                    using (EwsServiceXmlWriter writer = new EwsServiceXmlWriter(this.Service, requestStream))
                    {
                        this.WriteToXml(writer);
                    }
                }
            }
            else if (this.Service.RenderingMethod == ExchangeService.RenderingMode.JSON)
            {
                JsonObject requestObject = this.CreateJsonRequest();

                using (Stream serviceRequestStream = this.GetWebRequestStream(request))
                {
                    requestObject.SerializeToJson(serviceRequestStream);
                }
            }
        }