/// <summary> /// Returns an instance of the IODataRequestMessage /// </summary> /// <param name="requestMessageArgs">Arguments for creating the request message.</param> /// <returns>an instance of the IODataRequestMessage </returns> internal DataServiceClientRequestMessage CreateRequestMessage(BuildingRequestEventArgs requestMessageArgs) { var headersDictionary = requestMessageArgs.HeaderCollection.UnderlyingDictionary; // We are implementing the PostTunneling logic here. The reason for doing this is // 1> In this public class, the Method property returns the actual method (PUT, MERGE, DELETE), // and not the verb that goes in the wire. So this class needs to know about // actual verb since it will be using this verb to send over http. if (this.UsePostTunneling) { bool setXHttpMethodHeader = false; if (string.CompareOrdinal(XmlConstants.HttpMethodGet, requestMessageArgs.Method) != 0 && string.CompareOrdinal(XmlConstants.HttpMethodPost, requestMessageArgs.Method) != 0) { setXHttpMethodHeader = true; } // Setting the actual method in the header if (setXHttpMethodHeader) { headersDictionary[XmlConstants.HttpXMethod] = requestMessageArgs.Method; } // Set the Content-length of a Delete to 0. Important for post tunneling when its a post, content-length must be zero in this case. if (string.CompareOrdinal(XmlConstants.HttpMethodDelete, requestMessageArgs.Method) == 0) { headersDictionary[XmlConstants.HttpContentLength] = "0"; #if DEBUG if (!this.UserModifiedRequestInBuildingRequest) { Debug.Assert(!requestMessageArgs.HeaderCollection.HasHeader(XmlConstants.HttpContentType), "Content-Type header must not be set for DELETE requests"); } #endif } } #if !ASTORIA_LIGHT var clientRequestMessageArgs = new DataServiceClientRequestMessageArgs(requestMessageArgs.Method, requestMessageArgs.RequestUri, this.UseDefaultCredentials, this.UsePostTunneling, headersDictionary); #else var clientRequestMessageArgs = new DataServiceClientRequestMessageArgs(requestMessageArgs.Method, requestMessageArgs.RequestUri, this.UsePostTunneling, this.UseDefaultCredentials, headersDictionary, requestMessageArgs.ClientHttpStack); #endif DataServiceClientRequestMessage clientRequestMessage; if (this.Configurations.RequestPipeline.OnMessageCreating != null) { clientRequestMessage = this.Configurations.RequestPipeline.OnMessageCreating(clientRequestMessageArgs); if (clientRequestMessage == null) { throw Error.InvalidOperation(Strings.Context_OnMessageCreatingReturningNull); } } else { clientRequestMessage = new HttpWebRequestMessage(clientRequestMessageArgs, this); } return(clientRequestMessage); }
/// <summary> /// Create a request message for a non-batch requests and outer $batch request. This method copies request headers /// from <paramref name="requestMessageArgs"/> in addition to the method and Uri. /// </summary> /// <param name="requestMessageArgs">RequestMessageArgs for the request.</param> /// <param name="requestInfo">RequestInfo instance.</param> /// <returns>an instance of ODataRequestMessageWrapper.</returns> internal static ODataRequestMessageWrapper CreateRequestMessageWrapper(BuildingRequestEventArgs requestMessageArgs, RequestInfo requestInfo) { Debug.Assert(requestMessageArgs != null, "requestMessageArgs != null"); var requestMessage = requestInfo.CreateRequestMessage(requestMessageArgs); if (null != requestInfo.Credentials) { requestMessage.Credentials = requestInfo.Credentials; } #if !ASTORIA_LIGHT && !PORTABLELIB // Timeout not available if (0 != requestInfo.Timeout) { requestMessage.Timeout = requestInfo.Timeout; } #endif return(new TopLevelRequestMessageWrapper(requestMessage, requestInfo, requestMessageArgs.Descriptor)); }
/// <summary> /// Create a request message for a batch part from the batch writer. This method copies request headers /// from <paramref name="requestMessageArgs"/> in addition to the method and Uri. /// </summary> /// <param name="batchWriter">ODataBatchWriter instance to build operation message from.</param> /// <param name="requestMessageArgs">RequestMessageArgs for the request.</param> /// <param name="requestInfo">RequestInfo instance.</param> /// <returns>an instance of ODataRequestMessageWrapper.</returns> internal static ODataRequestMessageWrapper CreateBatchPartRequestMessage( ODataBatchWriter batchWriter, BuildingRequestEventArgs requestMessageArgs, RequestInfo requestInfo) { IODataRequestMessage requestMessage = batchWriter.CreateOperationRequestMessage(requestMessageArgs.Method, requestMessageArgs.RequestUri); #if WINDOWS_PHONE if (requestInfo.HasWritingRequestEventHandlers) { // We use the InternalODataRequestMessage constructor here beecause we want to allow the user to be able to access the underlying request stream. requestMessage = new InternalODataRequestMessage(requestMessage, true); } #endif foreach (var h in requestMessageArgs.Headers) { requestMessage.SetHeader(h.Key, h.Value); } var clientRequestMessage = new InternalODataRequestMessage(requestMessage, false /*allowGetStream*/); ODataRequestMessageWrapper messageWrapper = new InnerBatchRequestMessageWrapper(clientRequestMessage, requestMessage, requestInfo, requestMessageArgs.Descriptor); return(messageWrapper); }
/// <summary> /// Creates a request message with the given arguments. /// </summary> /// <param name="requestMessageArgs">The request message args.</param> /// <returns>Newly created request message.</returns> internal ODataRequestMessageWrapper CreateRequestMessage(BuildingRequestEventArgs requestMessageArgs) { return(ODataRequestMessageWrapper.CreateRequestMessageWrapper(requestMessageArgs, this.requestInfo)); }