Microsoft.Protocols.TestSuites.MS_OXCMAPIHTTP.MS_OXCMAPIHTTPAdapter.SendMAPIHttpRequest C# (CSharp) Method

SendMAPIHttpRequest() private method

This method is used to send the http request.
private SendMAPIHttpRequest ( string userName, string password, IRequestBody requestBody, ServerEndpoint endpoint, CookieCollection cookies, WebHeaderCollection resquestHeaders, byte &rawBuffer ) : HttpWebResponse
userName string The user name used to connect with server.
password string The password used to connect with server.
requestBody IRequestBody The request body.
endpoint ServerEndpoint The endpoint which the request would be send to.
cookies System.Net.CookieCollection Cookies used to identify the Session Context.
resquestHeaders System.Net.WebHeaderCollection The specified request header used by the request.
rawBuffer byte The raw buffer of the response.
return System.Net.HttpWebResponse
        private HttpWebResponse SendMAPIHttpRequest(string userName, string password, IRequestBody requestBody, ServerEndpoint endpoint, CookieCollection cookies, WebHeaderCollection resquestHeaders, out byte[] rawBuffer)
        {
            rawBuffer = null;
            HttpWebResponse response = null;
            AdapterHelper.Counter++;
            string url = string.Empty;
            if (endpoint == ServerEndpoint.MailboxServerEndpoint)
            {
                if (string.IsNullOrEmpty(this.mailStoreUrl))
                {
                    this.GetEndpointUrl();
                }

                url = this.mailStoreUrl;
            }
            else
            {
                if (string.IsNullOrEmpty(this.addressBookUrl))
                {
                    this.GetEndpointUrl();
                }

                url = this.addressBookUrl;
            }

            System.Net.ServicePointManager.ServerCertificateValidationCallback =
            new System.Net.Security.RemoteCertificateValidationCallback(Common.ValidateServerCertificate);
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ProtocolVersion = HttpVersion.Version11;
            request.ContentType = "application/mapi-http";
            request.Credentials = new NetworkCredential(userName, password, this.domainName);
            request.Headers.Add(resquestHeaders);
            request.CookieContainer.Add(cookies);
            request.Timeout = System.Threading.Timeout.Infinite;

            byte[] buffer = null;
            if (requestBody != null)
            {
                buffer = requestBody.Serialize();
                request.ContentLength = buffer.Length;
            }
            else
            {
                request.ContentLength = 0;
            }   

            if (requestBody != null)
            {
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(buffer, 0, buffer.Length);
                }
            }

            try
            {
                response = request.GetResponse() as HttpWebResponse;

                // Read the HTTP response buffer and parse the response to correct format.
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    rawBuffer = this.ReadHttpResponse(response);
                }
            }
            catch (WebException ex)
            {
                this.Site.Log.Add(
                    LogEntryKind.Comment, 
                    "A WebException happened when connecting the server, The exception is {0}.",
                    ex.Message);
                return (HttpWebResponse)ex.Response;
            }

            return response;
        }
MS_OXCMAPIHTTPAdapter