/// <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> /// Initialize bind request body. /// </summary> /// <param name="stat">The state of the request body.</param> /// <param name="flags">The flags of the request body.</param> /// <returns>The bind request body.</returns> private BindRequestBody BuildBindRequestBody(STAT stat, uint flags) { BindRequestBody bindRequestBody = new BindRequestBody(); bindRequestBody.State = stat; bindRequestBody.Flags = flags; bindRequestBody.HasState = true; byte[] auxIn = new byte[] { }; bindRequestBody.AuxiliaryBuffer = auxIn; bindRequestBody.AuxiliaryBufferSize = (uint)auxIn.Length; return bindRequestBody; }
/// <summary> /// Initiate a session between the client and the server. /// </summary> private void Bind() { STAT stat = new STAT(); stat.InitiateStat(); uint flags = 0x0; BindRequestBody bindRequestBody = new BindRequestBody(); bindRequestBody.State = stat; bindRequestBody.Flags = flags; bindRequestBody.HasState = true; byte[] auxIn = new byte[] { }; bindRequestBody.AuxiliaryBuffer = auxIn; bindRequestBody.AuxiliaryBufferSize = (uint)auxIn.Length; int responseCode; BindResponseBody bindResponseBody = this.Adapter.Bind(bindRequestBody, out responseCode); Site.Assert.AreEqual<uint>((uint)0, bindResponseBody.ErrorCode, "Bind operation should succeed and 0 is expected to be returned. The return value is {0}.", bindResponseBody.ErrorCode); }
/// <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; }