/// <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); }
/// <summary> /// Create message reader settings for consuming responses. /// </summary> /// <param name="entryXmlCustomizer">Optional XML entry customization callback to be used.</param> /// <returns>Newly created message reader settings.</returns> internal ODataMessageReaderSettings CreateSettings(Func <ODataEntry, XmlReader, Uri, XmlReader> entryXmlCustomizer) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); if (!this.responseInfo.ResponsePipeline.HasAtomReadingEntityHandlers) { entryXmlCustomizer = null; } Func <IEdmType, string, IEdmType> resolveWireTypeName = this.responseInfo.TypeResolver.ResolveWireTypeName; if (this.responseInfo.Context.Format.ServiceModel != null) { resolveWireTypeName = null; } settings.EnableWcfDataServicesClientBehavior( resolveWireTypeName, this.responseInfo.DataNamespace, UriUtil.UriToString(this.responseInfo.TypeScheme), entryXmlCustomizer); settings.BaseUri = this.responseInfo.BaseUriResolver.BaseUriOrNull; settings.MaxProtocolVersion = CommonUtil.ConvertToODataVersion(this.responseInfo.MaxProtocolVersion); settings.UndeclaredPropertyBehaviorKinds = this.responseInfo.UndeclaredPropertyBehaviorKinds | ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty; CommonUtil.SetDefaultMessageQuotas(settings.MessageQuotas); this.responseInfo.ResponsePipeline.ExecuteReaderSettingsConfiguration(settings); return(settings); }