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