GetFinalResponseCode() public static method

Get the final value of X-ResponseCode header.
public static GetFinalResponseCode ( string responseCode ) : uint
responseCode string The value of X-ResponseCode header returned from server.
return uint
        /// <summary>
        /// Send the request to address book server endpoint.
        /// </summary>
        /// <param name="requestBody">The request body.</param>
        /// <param name="requestType">The type of the request.</param>
        /// <param name="cookieChange">If the session context cookie changed.</param>
        /// <returns>The common response.</returns>
        private CommonResponse SendAddressBookRequest(IRequestBody requestBody, RequestType requestType, bool cookieChange = true)
        {
            byte[]              rawBuffer;
            CommonResponse      commonResponse      = null;
            WebHeaderCollection webHeaderCollection = AdapterHelper.InitializeHTTPHeader(requestType, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            // Send the Execute HTTP request and get the response.
            HttpWebResponse response     = this.SendMAPIHttpRequest(this.userName, this.password, requestBody, ServerEndpoint.AddressBookServerEndpoint, AdapterHelper.SessionContextCookies, webHeaderCollection, out rawBuffer);
            uint            responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            this.Site.Assert.AreEqual <uint>(0, responseCode, "The request to the address book server should be executed successfully!");

            // Read the HTTP response buffer and parse the response to correct format.
            commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);
            Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
            this.VerifyRequestTypesForAddressBookServerEndpoint(response.Headers, commonResponse);
            this.VerifyAutoDiscover(response.StatusCode, ServerEndpoint.AddressBookServerEndpoint);
            this.VerifyAuthentication(response);

            response.GetResponseStream().Close();
            if (cookieChange)
            {
                AdapterHelper.SessionContextCookies = response.Cookies;
            }

            return(commonResponse);
        }
        /// <summary>
        /// This method is used by the client to get specific properties on an object.
        /// </summary>
        /// <param name="getPropsRequestBody">The GetProps request type request body.</param>
        /// <param name="responseCodeHeader">The value of X-ResponseCode header</param>
        /// <returns>The response body of the GetProps request type.</returns>
        public GetPropsResponseBody GetProps(GetPropsRequestBody getPropsRequestBody, out uint responseCodeHeader)
        {
            byte[]              rawBuffer;
            CommonResponse      commonResponse      = null;
            WebHeaderCollection webHeaderCollection = AdapterHelper.InitializeHTTPHeader(RequestType.GetProps, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            // Send the Execute HTTP request and get the response.
            HttpWebResponse response = this.SendMAPIHttpRequest(this.userName, this.password, getPropsRequestBody, ServerEndpoint.AddressBookServerEndpoint, AdapterHelper.SessionContextCookies, webHeaderCollection, out rawBuffer);

            responseCodeHeader = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            // Read the HTTP response buffer and parse the response to correct format.
            commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);

            response.GetResponseStream().Close();
            AdapterHelper.SessionContextCookies = response.Cookies;
            GetPropsResponseBody getPropsResponseBody = new GetPropsResponseBody();

            if (commonResponse.ResponseBodyRawData.Length > 0)
            {
                getPropsResponseBody = GetPropsResponseBody.Parse(commonResponse.ResponseBodyRawData);
            }

            return(getPropsResponseBody);
        }
        /// <summary>
        /// This method is used by the client to establish a Session Context with the Address Book Server.
        /// </summary>
        /// <param name="bindRequestBody">The bind request type request body.</param>
        /// <param name="responseCode">The value of X-ResponseCode header of the bind response.</param>
        /// <returns>The response body of bind request type.</returns>
        public BindResponseBody Bind(BindRequestBody bindRequestBody, out int responseCode)
        {
            byte[]           rawBuffer        = null;
            CommonResponse   commonResponse   = null;
            BindResponseBody bindResponseBody = null;

            AdapterHelper.Counter        = 1;
            AdapterHelper.ClientInstance = Guid.NewGuid().ToString();
            WebHeaderCollection webHeaderCollection = AdapterHelper.InitializeHTTPHeader(RequestType.Bind, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            // Send the Execute HTTP request and get the response.
            HttpWebResponse response = this.SendMAPIHttpRequest(this.userName, this.password, bindRequestBody, ServerEndpoint.AddressBookServerEndpoint, AdapterHelper.SessionContextCookies, webHeaderCollection, out rawBuffer);

            responseCode = (int)AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            // Read the HTTP response buffer and parse the response to correct format.
            if (responseCode == 0)
            {
                commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);
                Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
                bindResponseBody = BindResponseBody.Parse(commonResponse.ResponseBodyRawData);
                this.VerifyBindResponseBody(bindResponseBody);
                this.VerifyAutoDiscover(response.StatusCode, ServerEndpoint.AddressBookServerEndpoint);
            }

            this.VerifyAuthentication(response);
            response.GetResponseStream().Close();
            AdapterHelper.SessionContextCookies = response.Cookies;

            return(bindResponseBody);
        }
        /// <summary>
        /// This method allows a client to determine whether a server's endpoint is reachable and operational.
        /// </summary>
        /// <param name="endpoint">The endpoint used by PING request.</param>
        /// <param name="metatags">The meta tags in the response body of the Ping request type.</param>
        /// <param name="headers">The request and response header of the PING request type.</param>
        /// <returns>The status code of the PING request type.</returns>
        public uint PING(ServerEndpoint endpoint, out List <string> metatags, out WebHeaderCollection headers)
        {
            metatags = null;
            byte[] rawBuffer;
            WebHeaderCollection webHeaderCollection = AdapterHelper.InitializeHTTPHeader(RequestType.PING, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            // Send the PING HTTP request and get the response.
            HttpWebResponse response = this.SendMAPIHttpRequest(this.userName, this.password, null, endpoint, AdapterHelper.SessionContextCookies, webHeaderCollection, out rawBuffer);

            headers = response.Headers;

            // Read the HTTP response buffer and parse the response to correct format.
            uint responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            CommonResponse commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);

            if (responseCode == 0)
            {
                // PING succeeded when the response code equals zero and PING request has no response body.
                metatags = commonResponse.MetaTags;
                this.VerifyHTTPS(response);
                this.VerifyAuthentication(response);
                this.VerifyAutoDiscover(response.StatusCode, endpoint);
                this.VerifyHTTPHeaders(response.Headers);
                this.VerifyAdditionalHeaders(commonResponse.AdditionalHeaders);
                this.VerifyPINGRequestType(commonResponse, endpoint, responseCode);
                this.VerifyResponseMetaTags(commonResponse.MetaTags);
            }

            this.VerifyContentTypeHeader(response.Headers);
            this.VerifyRespondingToAllRequestTypeRequests(response, commonResponse, responseCode);
            response.GetResponseStream().Close();
            return(responseCode);
        }
        /// <summary>
        /// This method is used by the client to delete a Session Context with the server.
        /// </summary>
        /// <param name="responseBody">The response body of the Disconnect request type.</param>
        /// <returns>The status code of the Disconnect request type.</returns>
        public uint Disconnect(out MailboxResponseBodyBase responseBody)
        {
            responseBody = null;
            byte[] rawBuffer;

            // Prepare the disconnect request body.
            DisconnectRequestBody disconnectRequestBody = new DisconnectRequestBody();

            byte[] rgbAuxIn = new byte[] { };
            disconnectRequestBody.AuxiliaryBufferSize = (uint)rgbAuxIn.Length;
            disconnectRequestBody.AuxiliaryBuffer     = rgbAuxIn;
            WebHeaderCollection webHeaderCollection = AdapterHelper.InitializeHTTPHeader(RequestType.Disconnect, AdapterHelper.ClientInstance, AdapterHelper.Counter);

            // Send the disconnect HTTP request and get the response.
            HttpWebResponse response     = this.SendMAPIHttpRequest(this.userName, this.password, disconnectRequestBody, ServerEndpoint.MailboxServerEndpoint, AdapterHelper.SessionContextCookies, webHeaderCollection, out rawBuffer);
            uint            responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            // Read the HTTP response buffer and parse the response to correct format.
            CommonResponse commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);

            if (responseCode == 0)
            {
                Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
                uint statusCode = BitConverter.ToUInt32(commonResponse.ResponseBodyRawData, 0);
                if (statusCode == 0)
                {
                    // Disconnect succeeded when the StatusCode field equals zero.
                    DisconnectSuccessResponseBody responseSuccess = DisconnectSuccessResponseBody.Parse(commonResponse.ResponseBodyRawData);
                    responseBody = responseSuccess;

                    this.VerifyDisconnectSuccessResponseBody(responseSuccess);
                }

                this.VerifyHTTPS(response);
                this.VerifyAuthentication(response);
                this.VerifyAutoDiscover(response.StatusCode, ServerEndpoint.MailboxServerEndpoint);
                this.VerifyHTTPHeaders(response.Headers);
                this.VerifyAdditionalHeaders(commonResponse.AdditionalHeaders);
                this.VerifyDisconnectResponse(response);
                this.VerifyRequestTypesForMailboxServerEndpoint(response.Headers, commonResponse);
                this.VerifyResponseMetaTags(commonResponse.MetaTags);
            }

            this.VerifyContentTypeHeader(response.Headers);
            this.VerifyRespondingToAllRequestTypeRequests(response, commonResponse, responseCode);
            response.GetResponseStream().Close();
            AdapterHelper.SessionContextCookies = response.Cookies;
            return(responseCode);
        }
        /// <summary>
        /// This method is used by the client to request that the server notify the client when a processing request that takes an extended amount of time completes.
        /// </summary>
        /// <param name="notificationWaitRequestBody">The request body of the NotificationWait request type.</param>
        /// <param name="httpHeaders">The request and response header of the NotificationWait request type.</param>
        /// <param name="responseBody">The response body of the NotificationWait request type.</param>
        /// <param name="metatags">The meta tags of the NotificationWait request type.</param>
        /// <param name="additionalHeader">The additional headers in the Notification request type response.</param>
        /// <returns>The status code of the NotificationWait request type.</returns>
        public uint NotificationWait(NotificationWaitRequestBody notificationWaitRequestBody, ref WebHeaderCollection httpHeaders, out MailboxResponseBodyBase responseBody, out List <string> metatags, out Dictionary <string, string> additionalHeader)
        {
            responseBody = null;
            byte[] rawBuffer;

            // Send the NotificationWait HTTP request and get the response.
            HttpWebResponse response = this.SendMAPIHttpRequest(this.userName, this.password, notificationWaitRequestBody, ServerEndpoint.MailboxServerEndpoint, AdapterHelper.SessionContextCookies, httpHeaders, out rawBuffer);

            httpHeaders = response.Headers;
            uint responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            // Read the HTTP response buffer and parse the response to correct format.
            CommonResponse commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);

            metatags         = commonResponse.MetaTags;
            additionalHeader = commonResponse.AdditionalHeaders;
            if (responseCode == 0)
            {
                Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
                uint statusCode = BitConverter.ToUInt32(commonResponse.ResponseBodyRawData, 0);
                if (statusCode == 0)
                {
                    // Send the NotificationWait request succeeded when the StatusCode field equals zero.
                    NotificationWaitSuccessResponseBody responseSuccess = NotificationWaitSuccessResponseBody.Parse(commonResponse.ResponseBodyRawData);
                    responseBody = responseSuccess;

                    this.VerifyNotificationWaitSuccessResponseBody(responseSuccess);
                }

                this.VerifyHTTPS(response);
                this.VerifyAuthentication(response);
                this.VerifyAutoDiscover(response.StatusCode, ServerEndpoint.MailboxServerEndpoint);
                this.VerifyHTTPHeaders(response.Headers);
                this.VerifyAdditionalHeaders(commonResponse.AdditionalHeaders);
                this.VerifyRequestTypesForMailboxServerEndpoint(response.Headers, commonResponse);
                this.VerifyResponseMetaTags(commonResponse.MetaTags);
                this.VerifyNotificationWaitRequestType(response.Headers);
            }

            this.VerifyContentTypeHeader(response.Headers);
            this.VerifyRespondingToAllRequestTypeRequests(response, commonResponse, responseCode);
            response.GetResponseStream().Close();
            return(responseCode);
        }
        /// <summary>
        /// This method is used to establish a Session Context with the server with specified user.
        /// </summary>
        /// <param name="userName">The UserName used to connect with server.</param>
        /// <param name="password">The password used to connect with server.</param>
        /// <param name="userDN">The UserESSDN used to connect with server.</param>
        /// <param name="cookies">Cookies used to identify the Session Context.</param>
        /// <param name="responseBody">The response body of the Connect request type.</param>
        /// <param name="webHeaderCollection">The web headers of the Connect request type.</param>
        /// <param name="httpStatus">The HTTP call response status.</param>
        /// <returns>The status code of the Connect request type.</returns>
        public uint Connect(string userName, string password, string userDN, ref CookieCollection cookies, out MailboxResponseBodyBase responseBody, ref WebHeaderCollection webHeaderCollection, out HttpStatusCode httpStatus)
        {
            responseBody = null;
            byte[] rgbAuxIn = new byte[] { };
            byte[] rawBuffer;

            // Prepare the connect request body.
            ConnectRequestBody connectRequestBody = new ConnectRequestBody();

            connectRequestBody.UserDN              = userDN;
            connectRequestBody.Flags               = ConstValues.ConnectionFlag;
            connectRequestBody.Cpid                = ConstValues.CodePageId;
            connectRequestBody.LcidString          = ConstValues.DefaultLocale;
            connectRequestBody.LcidSort            = ConstValues.DefaultLocale;
            connectRequestBody.AuxiliaryBufferSize = (uint)rgbAuxIn.Length;
            connectRequestBody.AuxiliaryBuffer     = rgbAuxIn;

            // Send the HTTP request and get the HTTP response.
            HttpWebResponse response = this.SendMAPIHttpRequest(userName, password, connectRequestBody, ServerEndpoint.MailboxServerEndpoint, cookies, webHeaderCollection, out rawBuffer);

            webHeaderCollection = response.Headers;
            httpStatus          = response.StatusCode;
            uint responseCode = AdapterHelper.GetFinalResponseCode(response.Headers["X-ResponseCode"]);

            if (httpStatus != HttpStatusCode.OK)
            {
                return(0);
            }

            // Read the HTTP response buffer and parse the response to correct format.
            CommonResponse commonResponse = CommonResponse.ParseCommonResponse(rawBuffer);

            if (responseCode == 0)
            {
                Site.Assert.IsNotNull(commonResponse.ResponseBodyRawData, "The response body should contains data.");
                uint statusCode = BitConverter.ToUInt32(commonResponse.ResponseBodyRawData, 0);
                if (statusCode == 0)
                {
                    // Connect succeeded when the StatusCode field equals zero.
                    ConnectSuccessResponseBody responseSuccess = ConnectSuccessResponseBody.Parse(commonResponse.ResponseBodyRawData);
                    responseBody = responseSuccess;

                    this.VerifyConnectSuccessResponseBody(responseSuccess);
                }

                this.VerifyHTTPS(response);
                this.VerifyAuthentication(response);
                this.VerifyAutoDiscover(httpStatus, ServerEndpoint.MailboxServerEndpoint);
                this.VerifyHTTPHeaders(response.Headers);
                this.VerifyAdditionalHeaders(commonResponse.AdditionalHeaders);
                this.VerifyConnectResponse(response);
                this.VerifyConnectOrBindResponse(response.Headers);
                this.VerifyRequestTypesForMailboxServerEndpoint(response.Headers, commonResponse);
                this.VerifyResponseMetaTags(commonResponse.MetaTags);
            }

            this.VerifyRespondingToAllRequestTypeRequests(response, commonResponse, responseCode);
            response.GetResponseStream().Close();
            AdapterHelper.SessionContextCookies = response.Cookies;
            cookies = response.Cookies;
            return(responseCode);
        }