/// <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; }
/// <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; }