Ejemplo n.º 1
0
        /// <summary>
        /// Create message writer settings for producing requests.
        /// </summary>
        /// <param name="startEntryXmlCustomizationCallback">Optional XML entry customization callback to be used for the start of entries.</param>
        /// <param name="endEntryXmlCustomizationCallback">Optional XML entry customization callback to be used for the end of entries.</param>
        /// <param name="isBatchPartRequest">if set to <c>true</c> indicates that this is a part of a batch request.</param>
        /// <returns>Newly created message writer settings.</returns>
        internal ODataMessageWriterSettings CreateSettings(Func <ODataEntry, XmlWriter, XmlWriter> startEntryXmlCustomizationCallback, Action <ODataEntry, XmlWriter, XmlWriter> endEntryXmlCustomizationCallback, bool isBatchPartRequest)
        {
            ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings
            {
                CheckCharacters = false,
                Indent          = false,

                // For operations inside batch, we need to dispose the stream. For top level requests,
                // we do not need to dispose the stream. Since for inner batch requests, the request
                // message is an internal implementation of IODataRequestMessage in ODataLib,
                // we can do this here.
                DisableMessageStreamDisposal = !isBatchPartRequest
            };

            CommonUtil.SetDefaultMessageQuotas(writerSettings.MessageQuotas);

            // If no event handlers are registered, then don't provide the callbacks to ODataLib.
            if (!this.requestInfo.HasWritingEventHandlers)
            {
                startEntryXmlCustomizationCallback = null;
                endEntryXmlCustomizationCallback   = null;
            }

            // Enable the Astoria client behavior in ODataLib.
            writerSettings.EnableWcfDataServicesClientBehavior(startEntryXmlCustomizationCallback, endEntryXmlCustomizationCallback, this.requestInfo.DataNamespace, this.requestInfo.TypeScheme.AbsoluteUri);

            this.requestInfo.Configurations.RequestPipeline.ExecuteWriterSettingsConfiguration(writerSettings);

            return(writerSettings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create message writer settings for producing requests.
        /// </summary>
        /// <param name="isBatchPartRequest">if set to <c>true</c> indicates that this is a part of a batch request.</param>
        /// <param name="enableAtom">Whether to enable ATOM.</param>
        /// <returns>Newly created message writer settings.</returns>
        internal ODataMessageWriterSettings CreateSettings(bool isBatchPartRequest, bool enableAtom)
        {
            ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings
            {
                CheckCharacters = false,
                Indent          = false,

                // For operations inside batch, we need to dispose the stream. For top level requests,
                // we do not need to dispose the stream. Since for inner batch requests, the request
                // message is an internal implementation of IODataRequestMessage in ODataLib,
                // we can do this here.
                DisableMessageStreamDisposal = !isBatchPartRequest
            };

#if !WINRT
            if (enableAtom)
            {
                // Enable ATOM for client
                writerSettings.EnableAtomSupport();
            }
#endif
            CommonUtil.SetDefaultMessageQuotas(writerSettings.MessageQuotas);

            // Enable the Astoria client behavior in ODataLib.
            writerSettings.EnableWcfDataServicesClientBehavior();

            this.requestInfo.Configurations.RequestPipeline.ExecuteWriterSettingsConfiguration(writerSettings);

            return(writerSettings);
        }
Ejemplo n.º 3
0
        internal static ODataMessageWriter CreateMessageWriter(ODataRequestMessageWrapper requestMessage, RequestInfo requestInfo)
        {
            ODataMessageWriterSettings writerSettings = new ODataMessageWriterSettings {
                CheckCharacters = false,
                Indent          = false,
                DisableMessageStreamDisposal = !requestMessage.IsBatchPartRequest
            };

            if (requestInfo.HasWritingEventHandlers)
            {
                writerSettings.EnableWcfDataServicesClientBehavior(new Func <ODataEntry, XmlWriter, XmlWriter>(Serializer.StartEntryXmlCustomizer), new Action <ODataEntry, XmlWriter, XmlWriter>(Serializer.EndEntryXmlCustomizer), requestInfo.DataNamespace, requestInfo.TypeScheme.AbsoluteUri);
            }
            else
            {
                writerSettings.EnableWcfDataServicesClientBehavior(null, null, requestInfo.DataNamespace, requestInfo.TypeScheme.AbsoluteUri);
            }
            return(requestMessage.CreateWriter(writerSettings));
        }