/// <summary>
        /// Begins processing a request received via a binary encoded channel.
        /// </summary>
        /// <param name="channeId">A unique identifier for the secure channel which is the source of the request.</param>
        /// <param name="endpointDescription">The description of the endpoint which the secure channel is using.</param>
        /// <param name="request">The incoming request.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="callbackData">The callback data.</param>
        /// <returns>
        /// The result which must be passed to the EndProcessRequest method.
        /// </returns>
        /// <seealso cref="EndProcessRequest"/>
        /// <seealso cref="ITransportListener"/>
        public IAsyncResult BeginProcessRequest(
            string channeId,
            EndpointDescription endpointDescription,
            IServiceRequest request,
            AsyncCallback callback,
            object callbackData)
        {
            if (channeId == null)
            {
                throw new ArgumentNullException(nameof(channeId));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // create operation.
            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);

            SecureChannelContext context = new SecureChannelContext(
                channeId,
                endpointDescription,
                RequestEncoding.Binary);

            // begin invoke service.
            return(result.BeginProcessRequest(context, request));
        }
/// <summary>
/// Asynchronously calls the _NAME_ service.
/// </summary>
    public virtual IAsyncResult Begin_NAME_(_NAME_Message message, AsyncCallback callback, object callbackData)
    {
        try
        {
            OnRequestReceived(message._NAME_Request);

            // check for bad data.
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            // set the request context.
            SetRequestContext(RequestEncoding.Xml);

            // create handler.
            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);
            return(result.BeginProcessRequest(SecureChannelContext.Current, message._NAME_Request));
        }
        catch (Exception e)
        {
            Exception fault = CreateSoapFault(message._NAME_Request, e);
            OnResponseFaultSent(fault);
            throw fault;
        }
    }
Exemple #3
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            // Close the client with a clear message when the app is shut down
            _cancellationTokenRegistration = _shutdownDetector.Token.Register(() =>
            {
                TerminateClient(String.Format(CultureInfo.CurrentCulture, Resources.LogStream_AppShutdown, Environment.NewLine, DateTime.UtcNow.ToString("s")));
            });

            string path = ParseRequest(context);

            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(context, cb, extraData);

            WriteInitialMessage(context);

            lock (_thisLock)
            {
                _results.Add(result);

                Initialize(path);
            }

            // enable application diagnostic trace automatically if connecting to root or application path
            // it will be turn off automatically every 24 hours
            if (_enableTrace)
            {
                _operationLock.LockOperation(() =>
                {
                    var diagnostics = new DiagnosticsSettingsManager(Path.Combine(_environment.DiagnosticsPath, Constants.SettingsJsonFile), _tracer);
                    diagnostics.UpdateSetting(AzureDriveEnabledKey, true);
                }, "Updating diagnostics setting", TimeSpan.FromSeconds(30));
            }

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Begins processing a request received via a binary encoded channel.
        /// </summary>
        /// <param name="channeId">A unique identifier for the secure channel which is the source of the request.</param>
        /// <param name="endpointDescription">The description of the endpoint which the secure channel is using.</param>
        /// <param name="request">The incoming request.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="callbackData">The callback data.</param>
        /// <returns>
        /// The result which must be passed to the EndProcessRequest method.
        /// </returns>
        /// <seealso cref="EndProcessRequest"/>
        /// <seealso cref="ITransportListener"/>
        public IAsyncResult BeginProcessRequest(
            string channeId,
            EndpointDescription endpointDescription,
            IServiceRequest request,
            AsyncCallback callback,
            object callbackData,
            System.Net.IPAddress remoteIP,  // HONEYPOT
            int remotePort)                 // HONEYPOT
        {
            if (channeId == null)
            {
                throw new ArgumentNullException("channeId");
            }
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            // create operation.
            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);

            SecureChannelContext context = new SecureChannelContext(
                channeId,
                endpointDescription,
                RequestEncoding.Binary,
                remoteIP,                   // HONEYPOT - pass remote IP and port to constructor
                remotePort
                );

            // begin invoke service.
            return(result.BeginProcessRequest(context, request));
        }
Exemple #5
0
 internal void AddPendingRequest(requestType request, ProcessRequestAsyncResult requestAsyncResult)
 {
     lock (_pendingRequests)
     {
         _pendingRequests.Add(request.requestId, requestAsyncResult);
     }
 }
            /// <summary>
            /// Checks for a valid IAsyncResult object and returns the original request object.
            /// </summary>
            /// <param name="ar">The IAsyncResult object for the operation.</param>
            /// <returns>The request object if available; otherwise null.</returns>
            public static IServiceRequest GetRequest(IAsyncResult ar)
            {
                ProcessRequestAsyncResult result = ar as ProcessRequestAsyncResult;

                if (result != null)
                {
                    return(result.m_request);
                }

                return(null);
            }
/// <summary>
/// Waits for an asynchronous call to the _NAME_ service to complete.
/// </summary>
    public virtual _NAME_ResponseMessage End_NAME_(IAsyncResult ar)
    {
        try
        {
            IServiceResponse response = ProcessRequestAsyncResult.WaitForComplete(ar, true);
            OnResponseSent(response);
            return(new _NAME_ResponseMessage((_NAME_Response)response));
        }
        catch (Exception e)
        {
            Exception fault = CreateSoapFault(ProcessRequestAsyncResult.GetRequest(ar), e);
            OnResponseFaultSent(fault);
            throw fault;
        }
    }
Exemple #8
0
        /// <summary>
        /// Dispatches an incoming binary encoded request.
        /// </summary>
        /// <param name="ar">The ar.</param>
        /// <returns></returns>
        public virtual InvokeServiceResponseMessage EndInvokeService(IAsyncResult ar)
        {
            try {
                // wait for the response.
                IServiceResponse response = ProcessRequestAsyncResult.WaitForComplete(ar, false);

                // encode the repsonse.
                InvokeServiceResponseMessage outgoing = new InvokeServiceResponseMessage();
                outgoing.InvokeServiceResponse = BinaryEncoder.EncodeMessage(response, MessageContext);
                return(outgoing);
            } catch (Exception e) {
                // create fault.
                ServiceFault fault = CreateFault(ProcessRequestAsyncResult.GetRequest(ar), e);

                // encode the fault as a response.
                InvokeServiceResponseMessage outgoing = new InvokeServiceResponseMessage();
                outgoing.InvokeServiceResponse = BinaryEncoder.EncodeMessage(fault, MessageContext);
                return(outgoing);
            }
        }
Exemple #9
0
        /// <summary>
        /// Dispatches an incoming binary encoded request.
        /// </summary>
        public virtual IAsyncResult BeginInvokeService(InvokeServiceMessage message, AsyncCallback callack,
                                                       object callbackData)
        {
            try {
                // check for bad data.
                if (message == null)
                {
                    throw new ServiceResultException(StatusCodes.BadInvalidArgument);
                }

                // set the request context.
                SetRequestContext(RequestEncoding.Binary);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callack, callbackData, 0);
                return(result.BeginProcessRequest(SecureChannelContext.Current, message.InvokeServiceRequest));
            } catch (Exception e) {
                throw CreateSoapFault(null, e);
            }
        }
Exemple #10
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            // Close the client with a clear message when the app is shut down
            _cancellationTokenRegistration = _shutdownDetector.Token.Register(() =>
            {
                TerminateClient(String.Format(CultureInfo.CurrentCulture, Resources.LogStream_AppShutdown, Environment.NewLine, DateTime.UtcNow.ToString("s")));
            });

            string path = ParseRequest(context);

            if (!Directory.Exists(path))
            {
                throw new HttpException((Int32)HttpStatusCode.NotFound, string.Format("The directory name {0} does not exist.", path));
            }

            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(context, cb, extraData);

            WriteInitialMessage(context);

            lock (_thisLock)
            {
                _results.Add(result);

                Initialize(path);
            }

            // enable application diagnostic trace automatically if connecting to root or application path
            // it will be turn off automatically every 24 hours
            if (_enableTrace)
            {
                _operationLock.LockOperation(() =>
                {
                    var settings = new JsonSettings(Path.Combine(_environment.DiagnosticsPath, Constants.SettingsJsonFile));
                    settings.SetValue(AzureDriveEnabledKey, true);
                }, TimeSpan.FromSeconds(30));
            }

            return(result);
        }
Exemple #11
0
        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            string path = GetFilePath(context);

            if (!Directory.Exists(path))
            {
                throw new HttpException((Int32)HttpStatusCode.NotFound, string.Format("The directory name {0} does not exist.", path));
            }

            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(context, cb, extraData);

            WriteInitialMessage(context);

            lock (_thisLock)
            {
                _results.Add(result);

                Initialize(path);
            }

            return(result);
        }
            /// <summary>
            /// Checks for a valid IAsyncResult object and waits for the operation to complete.
            /// </summary>
            /// <param name="ar">The IAsyncResult object for the operation.</param>
            /// <param name="throwOnError">if set to <c>true</c> an exception is thrown if an error occurred.</param>
            /// <returns>The response.</returns>
            public static IServiceResponse WaitForComplete(IAsyncResult ar, bool throwOnError)
            {
                ProcessRequestAsyncResult result = ar as ProcessRequestAsyncResult;

                if (result == null)
                {
                    throw new ArgumentException("End called with an invalid IAsyncResult object.", nameof(ar));
                }

                if (result.m_response == null)
                {
                    if (!result.WaitForComplete())
                    {
                        throw new TimeoutException();
                    }
                }

                if (throwOnError && result.m_error != null)
                {
                    throw new ServiceResultException(result.m_error, StatusCodes.BadInternalError);
                }

                return(result.m_response);
            }
        /// <summary>
        /// Begins processing a request received via a binary encoded channel.
        /// </summary>
        /// <param name="channeId">A unique identifier for the secure channel which is the source of the request.</param>
        /// <param name="endpointDescription">The description of the endpoint which the secure channel is using.</param>
        /// <param name="request">The incoming request.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="callbackData">The callback data.</param>
        /// <returns>
        /// The result which must be passed to the EndProcessRequest method.
        /// </returns>
        /// <seealso cref="EndProcessRequest"/>
        /// <seealso cref="ITransportListener"/>
        public IAsyncResult BeginProcessRequest(
            string channeId,
            EndpointDescription endpointDescription,
            IServiceRequest request,
            AsyncCallback callback,
            object callbackData)
        {
            if (channeId == null) throw new ArgumentNullException("channeId");
            if (request == null) throw new ArgumentNullException("request");

            // create operation.
            ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);

            SecureChannelContext context = new SecureChannelContext(
                channeId,
                endpointDescription,
                RequestEncoding.Binary);

            // begin invoke service.
            return result.BeginProcessRequest(context, request);
        }
        /// <summary>
        /// Dispatches an incoming binary encoded request.
        /// </summary>
        public virtual IAsyncResult BeginInvokeService(InvokeServiceMessage message, AsyncCallback callack, object callbackData)
        {
            try
            {
                // check for bad data.
                if (message == null)
                {
                    throw new ServiceResultException(StatusCodes.BadInvalidArgument);
                }
                
                // set the request context.
                SetRequestContext(RequestEncoding.Binary);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callack, callbackData, 0);
                return result.BeginProcessRequest(SecureChannelContext.Current, message.InvokeServiceRequest);
            }
            catch (Exception e)
            {
                throw CreateSoapFault(null, e);
            }
        }
Exemple #15
0
        /// <summary>
        /// Asynchronously calls the Cancel service.
        /// </summary>
        public virtual IAsyncResult BeginCancel(CancelMessage message, AsyncCallback callback, object callbackData)
        {
            try
            {
                // OnRequestReceived(message.CancelRequest);

                // check for bad data.
                if (message == null) throw new ArgumentNullException("message");

                // set the request context.
                SetRequestContext(RequestEncoding.Xml);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);
                return result.BeginProcessRequest(SecureChannelContext.Current, message.CancelRequest);
            }
            catch (Exception e)
            {
                Exception fault = CreateSoapFault(message.CancelRequest, e);
                // OnResponseFaultSent(fault);
                throw fault;
            }
        }
 /// <summary>
 /// Ends processing a request received via a binary encoded channel.
 /// </summary>
 /// <param name="result">The result returned by the BeginProcessRequest method.</param>
 /// <returns>
 /// The response to return over the secure channel.
 /// </returns>
 /// <seealso cref="BeginProcessRequest"/>
 public IServiceResponse EndProcessRequest(IAsyncResult result)
 {
     return(ProcessRequestAsyncResult.WaitForComplete(result, false));
 }
Exemple #17
0
 public void EndProcessRequest(IAsyncResult result)
 {
     ProcessRequestAsyncResult.End(result);
 }
Exemple #18
0
        /// <summary>
        /// Asynchronously calls the DeleteReferences service.
        /// </summary>
        public virtual IAsyncResult BeginDeleteReferences(DeleteReferencesMessage message, AsyncCallback callback, object callbackData)
        {
            try
            {
                // check for bad data.
                if (message == null) throw new ArgumentNullException("message");

                // set the request context.
                SetRequestContext(RequestEncoding.Xml);

                // create handler.
                ProcessRequestAsyncResult result = new ProcessRequestAsyncResult(this, callback, callbackData, 0);
                return result.BeginProcessRequest(SecureChannelContext.Current, message.DeleteReferencesRequest);
            }
            catch (Exception e)
            {
                throw CreateSoapFault(message.DeleteReferencesRequest, e);
            }
        }
Exemple #19
0
        public void EndProcessRequest(IAsyncResult result)
        {
            ProcessRequestAsyncResult.End(result);

            _cancellationTokenRegistration.Dispose();
        }