public override DirectoryResponse SendRequest(DirectoryRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            DsmlRequestDocument document = new DsmlRequestDocument();

            document.Add(request);
            DsmlResponseDocument document2 = this.SendRequestHelper(document.ToXml().InnerXml);

            if (document2.Count == 0)
            {
                throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingResponse"));
            }
            DirectoryResponse response = document2[0];

            if (response is DsmlErrorResponse)
            {
                ErrorResponseException exception = new ErrorResponseException((DsmlErrorResponse)response);
                throw exception;
            }
            ResultCode resultCode = response.ResultCode;

            if (((resultCode != ResultCode.Success) && (resultCode != ResultCode.CompareFalse)) && (((resultCode != ResultCode.CompareTrue) && (resultCode != ResultCode.Referral)) && (resultCode != ResultCode.ReferralV2)))
            {
                throw new DirectoryOperationException(response, OperationErrorMappings.MapResultCode((int)resultCode));
            }
            return(response);
        }
        public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            if (!(asyncResult is DsmlAsyncResult))
            {
                throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("NotReturnedAsyncResult", new object[] { "asyncResult" }));
            }
            if (!this.httpConnectionTable.Contains(asyncResult))
            {
                throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("InvalidAsyncResult"));
            }
            this.httpConnectionTable.Remove(asyncResult);
            DsmlAsyncResult result = (DsmlAsyncResult)asyncResult;

            asyncResult.AsyncWaitHandle.WaitOne();
            if (result.resultObject.exception != null)
            {
                throw result.resultObject.exception;
            }
            DsmlResponseDocument document = new DsmlResponseDocument(result.resultObject.responseString, "se:Envelope/se:Body/dsml:batchResponse");

            this.debugResponse = document.ResponseString;
            if (result.hasValidRequest && (document.Count == 0))
            {
                throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingResponse"));
            }
            return(document);
        }
        public DsmlResponseDocument SendRequest(DsmlRequestDocument request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            DsmlResponseDocument document = this.SendRequestHelper(request.ToXml().InnerXml);

            if ((request.Count > 0) && (document.Count == 0))
            {
                throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingResponse"));
            }
            return(document);
        }
示例#4
0
        public DsmlResponseDocument SendRequest(DsmlRequestDocument request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            DsmlResponseDocument responseDoc = SendRequestHelper(request.ToXml().InnerXml);

            if (request.Count > 0 && responseDoc.Count == 0)
            {
                throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingResponse));
            }

            return(responseDoc);
        }
示例#5
0
        public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            if (!(asyncResult is DsmlAsyncResult))
            {
                throw new ArgumentException(Res.GetString(Res.NotReturnedAsyncResult, "asyncResult"));
            }

            if (!_httpConnectionTable.Contains(asyncResult))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));
            }

            // remove the asyncResult from our connection table
            _httpConnectionTable.Remove(asyncResult);

            DsmlAsyncResult result = (DsmlAsyncResult)asyncResult;

            asyncResult.AsyncWaitHandle.WaitOne();

            // Process the response

            // see if any exception occurs, if yes, then throw the exception
            if (result.resultObject.exception != null)
            {
                throw result.resultObject.exception;
            }

            DsmlResponseDocument dsmlResponseDoc = new DsmlResponseDocument(
                result.resultObject.responseString,
                "se:Envelope/se:Body/dsml:batchResponse"
                );

            _debugResponse = dsmlResponseDoc.ResponseString;

            // validate the response
            if (result.hasValidRequest && dsmlResponseDoc.Count == 0)
            {
                throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingResponse));
            }

            return(dsmlResponseDoc);
        }
 public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
 {
     if (asyncResult != null)
     {
         if (asyncResult as DsmlAsyncResult != null)
         {
             if (this.httpConnectionTable.Contains(asyncResult))
             {
                 this.httpConnectionTable.Remove(asyncResult);
                 DsmlAsyncResult dsmlAsyncResult = (DsmlAsyncResult)asyncResult;
                 asyncResult.AsyncWaitHandle.WaitOne();
                 if (dsmlAsyncResult.resultObject.exception == null)
                 {
                     DsmlResponseDocument dsmlResponseDocuments = new DsmlResponseDocument(dsmlAsyncResult.resultObject.responseString, "se:Envelope/se:Body/dsml:batchResponse");
                     this.debugResponse = dsmlResponseDocuments.ResponseString;
                     if (!dsmlAsyncResult.hasValidRequest || dsmlResponseDocuments.Count != 0)
                     {
                         return(dsmlResponseDocuments);
                     }
                     else
                     {
                         throw new DsmlInvalidDocumentException(Res.GetString("MissingResponse"));
                     }
                 }
                 else
                 {
                     throw dsmlAsyncResult.resultObject.exception;
                 }
             }
             else
             {
                 throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
             }
         }
         else
         {
             object[] objArray = new object[1];
             objArray[0] = "asyncResult";
             throw new ArgumentException(Res.GetString("NotReturnedAsyncResult", objArray));
         }
     }
     else
     {
         throw new ArgumentNullException("asyncResult");
     }
 }
 public DsmlResponseDocument SendRequest(DsmlRequestDocument request)
 {
     if (request != null)
     {
         DsmlResponseDocument dsmlResponseDocuments = this.SendRequestHelper(request.ToXml().InnerXml);
         if (request.Count <= 0 || dsmlResponseDocuments.Count != 0)
         {
             return(dsmlResponseDocuments);
         }
         else
         {
             throw new DsmlInvalidDocumentException(Res.GetString("MissingResponse"));
         }
     }
     else
     {
         throw new ArgumentNullException("request");
     }
 }
        private DsmlResponseDocument SendRequestHelper(string reqstring)
        {
            DsmlResponseDocument dsmlResponseDocuments;
            DsmlResponseDocument dsmlResponseDocuments1;
            StringBuilder        stringBuilder = new StringBuilder(0x400);

            try
            {
                this.PrepareHttpWebRequest(this.dsmlHttpConnection);
                StreamWriter webRequestStreamWriter = this.GetWebRequestStreamWriter();
                try
                {
                    this.BeginSOAPRequest(ref stringBuilder);
                    stringBuilder.Append(reqstring);
                    this.EndSOAPRequest(ref stringBuilder);
                    webRequestStreamWriter.Write(stringBuilder.ToString());
                    webRequestStreamWriter.Flush();
                }
                finally
                {
                    webRequestStreamWriter.BaseStream.Close();
                    webRequestStreamWriter.Close();
                }
                HttpWebResponse response = (HttpWebResponse)this.dsmlHttpConnection.GetResponse();
                try
                {
                    dsmlResponseDocuments = new DsmlResponseDocument(response, "se:Envelope/se:Body/dsml:batchResponse");
                    this.debugResponse    = dsmlResponseDocuments.ResponseString;
                }
                finally
                {
                    response.Close();
                }
                dsmlResponseDocuments1 = dsmlResponseDocuments;
            }
            finally
            {
                this.dsmlHttpConnection = (HttpWebRequest)WebRequest.Create(((DsmlDirectoryIdentifier)this.directoryIdentifier).ServerUri);
            }
            return(dsmlResponseDocuments1);
        }
示例#9
0
        public override DirectoryResponse SendRequest(DirectoryRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            DsmlRequestDocument doc = new DsmlRequestDocument();

            doc.Add(request);

            DsmlResponseDocument response = SendRequestHelper(doc.ToXml().InnerXml);

            if (response.Count == 0)
            {
                throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingResponse));
            }

            DirectoryResponse result = response[0];

            if (result is DsmlErrorResponse)
            {
                // need to throw ErrorResponseException
                ErrorResponseException e = new ErrorResponseException((DsmlErrorResponse)result);
                throw e;
            }
            else
            {
                ResultCode error = result.ResultCode;
                if (error == ResultCode.Success || error == ResultCode.CompareFalse || error == ResultCode.CompareTrue || error == ResultCode.Referral || error == ResultCode.ReferralV2)
                {
                    return(result);
                }
                else
                {
                    throw new DirectoryOperationException(result, OperationErrorMappings.MapResultCode((int)error));
                }
            }
        }
 public override DirectoryResponse SendRequest(DirectoryRequest request)
 {
     if (request != null)
     {
         DsmlRequestDocument dsmlRequestDocuments = new DsmlRequestDocument();
         dsmlRequestDocuments.Add(request);
         DsmlResponseDocument dsmlResponseDocuments = this.SendRequestHelper(dsmlRequestDocuments.ToXml().InnerXml);
         if (dsmlResponseDocuments.Count != 0)
         {
             DirectoryResponse item = dsmlResponseDocuments[0];
             if (item as DsmlErrorResponse == null)
             {
                 ResultCode resultCode = item.ResultCode;
                 if (resultCode == ResultCode.Success || resultCode == ResultCode.CompareFalse || resultCode == ResultCode.CompareTrue || resultCode == ResultCode.Referral || resultCode == ResultCode.ReferralV2)
                 {
                     return(item);
                 }
                 else
                 {
                     throw new DirectoryOperationException(item, OperationErrorMappings.MapResultCode((int)resultCode));
                 }
             }
             else
             {
                 ErrorResponseException errorResponseException = new ErrorResponseException((DsmlErrorResponse)item);
                 throw errorResponseException;
             }
         }
         else
         {
             throw new DsmlInvalidDocumentException(Res.GetString("MissingResponse"));
         }
     }
     else
     {
         throw new ArgumentNullException("request");
     }
 }
 private DsmlResponseDocument SendRequestHelper(string reqstring)
 {
     DsmlResponseDocument document2;
     StringBuilder buffer = new StringBuilder(0x400);
     try
     {
         DsmlResponseDocument document;
         this.PrepareHttpWebRequest(this.dsmlHttpConnection);
         StreamWriter webRequestStreamWriter = this.GetWebRequestStreamWriter();
         try
         {
             this.BeginSOAPRequest(ref buffer);
             buffer.Append(reqstring);
             this.EndSOAPRequest(ref buffer);
             webRequestStreamWriter.Write(buffer.ToString());
             webRequestStreamWriter.Flush();
         }
         finally
         {
             webRequestStreamWriter.BaseStream.Close();
             webRequestStreamWriter.Close();
         }
         HttpWebResponse resp = (HttpWebResponse) this.dsmlHttpConnection.GetResponse();
         try
         {
             document = new DsmlResponseDocument(resp, "se:Envelope/se:Body/dsml:batchResponse");
             this.debugResponse = document.ResponseString;
         }
         finally
         {
             resp.Close();
         }
         document2 = document;
     }
     finally
     {
         this.dsmlHttpConnection = (HttpWebRequest) WebRequest.Create(((DsmlDirectoryIdentifier) base.directoryIdentifier).ServerUri);
     }
     return document2;
 }
 public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
 {
     if (asyncResult == null)
     {
         throw new ArgumentNullException("asyncResult");
     }
     if (!(asyncResult is DsmlAsyncResult))
     {
         throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("NotReturnedAsyncResult", new object[] { "asyncResult" }));
     }
     if (!this.httpConnectionTable.Contains(asyncResult))
     {
         throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("InvalidAsyncResult"));
     }
     this.httpConnectionTable.Remove(asyncResult);
     DsmlAsyncResult result = (DsmlAsyncResult) asyncResult;
     asyncResult.AsyncWaitHandle.WaitOne();
     if (result.resultObject.exception != null)
     {
         throw result.resultObject.exception;
     }
     DsmlResponseDocument document = new DsmlResponseDocument(result.resultObject.responseString, "se:Envelope/se:Body/dsml:batchResponse");
     this.debugResponse = document.ResponseString;
     if (result.hasValidRequest && (document.Count == 0))
     {
         throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingResponse"));
     }
     return document;
 }
示例#13
0
        private DsmlResponseDocument SendRequestHelper(string reqstring)
        {
            //
            // Request
            //
            StringBuilder requestBuffer = new StringBuilder(1024);

            try
            {
                // Do the generic preparation of the request
                PrepareHttpWebRequest(_dsmlHttpConnection);

                // Get the stream we're going to write to
                StreamWriter reqWriter = GetWebRequestStreamWriter();

                try
                {
                    // Begin the SOAP Envelope, attaching the sessionID if applicable
                    BeginSOAPRequest(ref requestBuffer);

                    // Write out the actual DSML v2 request
                    requestBuffer.Append(reqstring);

                    // Finish writing the SOAP Envelope
                    EndSOAPRequest(ref requestBuffer);

                    reqWriter.Write(requestBuffer.ToString());

                    // Close out the stream
                    reqWriter.Flush();
                }
                finally
                {
                    reqWriter.BaseStream.Close();
                    reqWriter.Close();
                }

                //
                // Response
                //

                // Actually send the request to the server, and retrieve the response
                // N.B.: we deliberately permit any exception to bubble up to the caller
                HttpWebResponse      dsmlResponse = (HttpWebResponse)_dsmlHttpConnection.GetResponse();
                DsmlResponseDocument dsmlResponseDoc;

                try
                {
                    // Process the response
                    dsmlResponseDoc = new DsmlResponseDocument(
                        dsmlResponse,
                        "se:Envelope/se:Body/dsml:batchResponse"
                        );
                    _debugResponse = dsmlResponseDoc.ResponseString;
                }
                finally
                {
                    dsmlResponse.Close();
                }

                return(dsmlResponseDoc);
            }
            finally
            {
                // create a fresh HttpWebRequest for the next operation
                // (HttpWebRequest objects can only be used once)
                _dsmlHttpConnection = (HttpWebRequest)WebRequest.Create(((DsmlDirectoryIdentifier)directoryIdentifier).ServerUri);
            }
        }
示例#14
0
        public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
                throw new ArgumentNullException("asyncResult");

            if (!(asyncResult is DsmlAsyncResult))
                throw new ArgumentException(Res.GetString(Res.NotReturnedAsyncResult, "asyncResult"));

            if (!_httpConnectionTable.Contains(asyncResult))
                throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));

            // remove the asyncResult from our connection table
            _httpConnectionTable.Remove(asyncResult);

            DsmlAsyncResult result = (DsmlAsyncResult)asyncResult;
            asyncResult.AsyncWaitHandle.WaitOne();

            // Process the response

            // see if any exception occurs, if yes, then throw the exception
            if (result.resultObject.exception != null)
                throw result.resultObject.exception;

            DsmlResponseDocument dsmlResponseDoc = new DsmlResponseDocument(
                                                       result.resultObject.responseString,
                                                       "se:Envelope/se:Body/dsml:batchResponse"
                                                       );
            _debugResponse = dsmlResponseDoc.ResponseString;

            // validate the response
            if (result.hasValidRequest && dsmlResponseDoc.Count == 0)
                throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingResponse));

            return dsmlResponseDoc;
        }
示例#15
0
        private DsmlResponseDocument SendRequestHelper(string reqstring)
        {
            //
            // Request
            //                        
            StringBuilder requestBuffer = new StringBuilder(1024);

            try
            {
                // Do the generic preparation of the request
                PrepareHttpWebRequest(_dsmlHttpConnection);

                // Get the stream we're going to write to
                StreamWriter reqWriter = GetWebRequestStreamWriter();

                try
                {
                    // Begin the SOAP Envelope, attaching the sessionID if applicable
                    BeginSOAPRequest(ref requestBuffer);

                    // Write out the actual DSML v2 request
                    requestBuffer.Append(reqstring);

                    // Finish writing the SOAP Envelope
                    EndSOAPRequest(ref requestBuffer);

                    reqWriter.Write(requestBuffer.ToString());

                    // Close out the stream
                    reqWriter.Flush();
                }
                finally
                {
                    reqWriter.BaseStream.Close();
                    reqWriter.Close();
                }

                //
                // Response
                //

                // Actually send the request to the server, and retrieve the response
                // N.B.: we deliberately permit any exception to bubble up to the caller
                HttpWebResponse dsmlResponse = (HttpWebResponse)_dsmlHttpConnection.GetResponse();
                DsmlResponseDocument dsmlResponseDoc;

                try
                {
                    // Process the response
                    dsmlResponseDoc = new DsmlResponseDocument(
                                                       dsmlResponse,
                                                       "se:Envelope/se:Body/dsml:batchResponse"
                                                        );
                    _debugResponse = dsmlResponseDoc.ResponseString;
                }
                finally
                {
                    dsmlResponse.Close();
                }

                return dsmlResponseDoc;
            }
            finally
            {
                // create a fresh HttpWebRequest for the next operation
                // (HttpWebRequest objects can only be used once)
                _dsmlHttpConnection = (HttpWebRequest)WebRequest.Create(((DsmlDirectoryIdentifier)directoryIdentifier).ServerUri);
            }
        }
示例#16
0
		public DsmlResponseDocument EndSendRequest(IAsyncResult asyncResult)
		{
			if (asyncResult != null)
			{
				if (asyncResult as DsmlAsyncResult != null)
				{
					if (this.httpConnectionTable.Contains(asyncResult))
					{
						this.httpConnectionTable.Remove(asyncResult);
						DsmlAsyncResult dsmlAsyncResult = (DsmlAsyncResult)asyncResult;
						asyncResult.AsyncWaitHandle.WaitOne();
						if (dsmlAsyncResult.resultObject.exception == null)
						{
							DsmlResponseDocument dsmlResponseDocuments = new DsmlResponseDocument(dsmlAsyncResult.resultObject.responseString, "se:Envelope/se:Body/dsml:batchResponse");
							this.debugResponse = dsmlResponseDocuments.ResponseString;
							if (!dsmlAsyncResult.hasValidRequest || dsmlResponseDocuments.Count != 0)
							{
								return dsmlResponseDocuments;
							}
							else
							{
								throw new DsmlInvalidDocumentException(Res.GetString("MissingResponse"));
							}
						}
						else
						{
							throw dsmlAsyncResult.resultObject.exception;
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
					}
				}
				else
				{
					object[] objArray = new object[1];
					objArray[0] = "asyncResult";
					throw new ArgumentException(Res.GetString("NotReturnedAsyncResult", objArray));
				}
			}
			else
			{
				throw new ArgumentNullException("asyncResult");
			}
		}