Microsoft.Protocols.TestSuites.Common.MessageInspector.BeforeSendRequest C# (CSharp) Method

BeforeSendRequest() public method

Implementation will add the headers for MS-WOPI before a request message is sent to a service.
public BeforeSendRequest ( System &request, System channel ) : object
request System Specify the message to be sent to the service.
channel System Specify the client object channel.
return object
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            // Restore the request.
            string requestString = request.ToString();
            XmlDocument requestXml = new XmlDocument();
            requestXml.LoadXml(requestString);
            SchemaValidation.LastRawRequestXml = requestXml.DocumentElement;

            // Create a clone message for the request.
            MessageBuffer messageBuffer = request.CreateBufferedCopy(int.MaxValue);
            request = messageBuffer.CreateMessage();

            if (this.context.OperationType == OperationType.WOPICellStorageRequest
                || this.context.OperationType == OperationType.WOPICellStorageRelativeRequest)
            {
                // Remove the SoapAction header
                request.Headers.RemoveAll("Action", "http://schemas.microsoft.com/ws/2005/05/addressing/none");

                // Add all the MUST header values
                this.AddHeader(ref request, "X-WOPI-Proof", this.context.XWOPIProof);
                this.AddHeader(ref request, "X-WOPI-TimeStamp", this.context.XWOPITimeStamp);
                this.AddHeader(ref request, "Authorization", this.context.XWOPIAuthorization);

                // Add all the optional value
                if (this.context.IsXWOPIOverrideSpecified)
                {
                    this.AddHeader(ref request, "X-WOPI-Override", this.context.GetValueOrDefault<string>("X-WOPI-Override", "COBALT"));
                }

                if (this.context.IsXWOPISizeSpecified)
                {
                    this.AddHeader(ref request, "X-WOPI-Size", this.context.GetValueOrDefault<int>("X-WOPI-Size", this.SizeOfWOPIMessage(messageBuffer.CreateMessage())).ToString());
                }

                if (this.context.OperationType == OperationType.WOPICellStorageRelativeRequest)
                {
                    if (this.context.IsXWOPIRelativeTargetSpecified)
                    {
                        this.AddHeader(ref request, "X-WOPI-RelativeTarget", this.context.XWOPIRelativeTarget);
                    }
                }
            }

            return null;
        }