/// <summary> /// Parse the response data into 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> /// Parse the response data into 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> /// The NspiBind method initiates a session between a client and the server. /// </summary> /// <param name="flags">A DWORD value that contains a set of bit flags.</param> /// <param name="stat">A STAT block that describes a logical position in a specific address book container.</param> /// <param name="serverGuid">The value NULL or a pointer to a GUID value that is associated with the specific server.</param> /// <returns>Status of NSPI method.</returns> public ErrorCodeValue Bind(uint flags, STAT stat, ref FlatUID_r?serverGuid) { ErrorCodeValue result; BindRequestBody bindRequestBody = this.BuildBindRequestBody(stat, flags); byte[] rawBuffer = null; ChunkedResponse chunkedResponse = null; BindResponseBody bindResponseBody = null; // Send the execute HTTP request and get the response HttpWebResponse response = MapiHttpAdapter.SendMAPIHttpRequest(this.site, this.addressBookUrl, this.userName, this.domainName, this.password, bindRequestBody, RequestType.Bind.ToString(), AdapterHelper.SessionContextCookies); // Read the HTTP response buffer and parse the response to correct format rawBuffer = MapiHttpAdapter.ReadHttpResponse(response); result = (ErrorCodeValue)int.Parse(response.Headers["X-ResponseCode"]); if (result == ErrorCodeValue.Success) { chunkedResponse = ChunkedResponse.ParseChunkedResponse(rawBuffer); bindResponseBody = BindResponseBody.Parse(chunkedResponse.ResponseBodyRawData); result = (ErrorCodeValue)bindResponseBody.ErrorCode; if (bindResponseBody.ServerGuid != null) { FlatUID_r newGuid = new FlatUID_r(); newGuid.Ab = bindResponseBody.ServerGuid.ToByteArray(); serverGuid = newGuid; } else { serverGuid = null; } } response.GetResponseStream().Close(); AdapterHelper.SessionContextCookies = response.Cookies; return(result); }