A class indicates the response body of bind request
Inheritance: AddressBookResponseBodyBase
        /// <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>
        /// Parse the Bind request type response body.
        /// </summary>
        /// <param name="rawData">The raw data of response.</param>
        /// <returns>The response body of bind request.</returns>
        public static BindResponseBody Parse(byte[] rawData)
        {
            BindResponseBody responseBody = new BindResponseBody();
            int index = 0;
            responseBody.StatusCode = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index);
            index += 4;

            byte[] serverGuidBytes = new byte[16];
            Array.Copy(rawData, index, serverGuidBytes, 0, 16);
            responseBody.ServerGuid = new Guid(serverGuidBytes);
            index += 16;
            responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize];
            Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize);
            return responseBody;
        }
Example #3
0
        /// <summary>
        /// Parse the Bind request type response body.
        /// </summary>
        /// <param name="rawData">The raw data of response.</param>
        /// <returns>The response body of bind request.</returns>
        public static BindResponseBody Parse(byte[] rawData)
        {
            BindResponseBody responseBody = new BindResponseBody();
            int index = 0;

            responseBody.StatusCode = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.ErrorCode = BitConverter.ToUInt32(rawData, index);
            index += 4;

            byte[] serverGuidBytes = new byte[16];
            Array.Copy(rawData, index, serverGuidBytes, 0, 16);
            responseBody.ServerGuid = new Guid(serverGuidBytes);
            index += 16;
            responseBody.AuxiliaryBufferSize = BitConverter.ToUInt32(rawData, index);
            index += 4;
            responseBody.AuxiliaryBuffer = new byte[responseBody.AuxiliaryBufferSize];
            Array.Copy(rawData, index, responseBody.AuxiliaryBuffer, 0, responseBody.AuxiliaryBufferSize);
            return(responseBody);
        }
        /// <summary>
        /// Verify the Bind response body related requirements.
        /// </summary>
        /// <param name="bindResponseBody">The Bind response body to be verified.</param>
        private void VerifyBindResponseBody(BindResponseBody bindResponseBody)
        {
            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R346");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R346
            this.Site.CaptureRequirementIfIsInstanceOfType(
                bindResponseBody.StatusCode,
                typeof(uint),
                346,
                @"[In Bind Request Type Response Body] StatusCode (4 bytes): An unsigned integer that specifies the status of the request.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R347");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R347
            this.Site.CaptureRequirementIfAreEqual<uint>(
                0,
                bindResponseBody.StatusCode,
                347,
                @"[In Bind Request Type Response Body] [StatusCode] This field MUST be set to 0x00000000.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R348");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R348
            this.Site.CaptureRequirementIfIsInstanceOfType(
                bindResponseBody.ErrorCode,
                typeof(uint),
                348,
                @"[In Bind Request Type Response Body] ErrorCode (4 bytes): An unsigned integer that specifies the return status of the operation.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R349");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R349
            this.Site.CaptureRequirementIfIsInstanceOfType(
                bindResponseBody.ServerGuid,
                typeof(Guid),
                349,
                @"[In Bind Request Type Response Body] ServerGuid (16 bytes): A GUID that is associated with a specific address book server.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R350");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R350
            this.Site.CaptureRequirementIfIsInstanceOfType(
                bindResponseBody.AuxiliaryBufferSize,
                typeof(uint),
                350,
                @"[In Bind Request Type Response Body] AuxiliaryBufferSize (4 bytes): An unsigned integer that specifies the size, in bytes, of the AuxiliaryBuffer field.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R351");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R351
            this.Site.CaptureRequirementIfIsInstanceOfType(
                bindResponseBody.AuxiliaryBuffer,
                typeof(byte[]),
                351,
                @"[In Bind Request Type Response Body] AuxiliaryBuffer (variable): An array of bytes that constitute the auxiliary payload data returned from the server.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R352");

            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R352
            this.Site.CaptureRequirementIfAreEqual<uint>(
                bindResponseBody.AuxiliaryBufferSize,
                (uint)bindResponseBody.AuxiliaryBuffer.Length,
                352,
                @"[In Bind Request Type Response Body] [AuxiliaryBuffer] The size of this field, in bytes, is specified by the AuxiliaryBufferSize field.");

            // Add the debug information
            this.Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXCMAPIHTTP_R1446");
        
            // Verify MS-OXCMAPIHTTP requirement: MS-OXCMAPIHTTP_R1446
            // If the response body is not null, it indicates that the server issues a response to a Bind request type.
            this.Site.CaptureRequirementIfIsNotNull(
                bindResponseBody,
                1446,
                @"[In Responding to a Connect or Bind Request Type Request] The server issues a response, as specified in section 2.2.2.2, to a Bind request type request, as specified in section 2.2.5.1.1.");
        }