Ejemplo n.º 1
0
        /// <summary>
        /// Creating a new instance of WcfLogReceiverClient
        ///
        /// Inheritors can override this method and provide their own
        /// service configuration - binding and endpoint address
        /// </summary>
        /// <returns></returns>
        protected virtual WcfLogReceiverClient CreateWcfLogReceiverClient()
        {
            WcfLogReceiverClient client;

            if (string.IsNullOrEmpty(this.EndpointConfigurationName))
            {
                // endpoint not specified - use BasicHttpBinding
                Binding binding;

                if (this.UseBinaryEncoding)
                {
                    binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
                }
                else
                {
                    binding = new BasicHttpBinding();
                }

                client = new WcfLogReceiverClient(binding, new EndpointAddress(this.EndpointAddress));
            }
            else
            {
                client = new WcfLogReceiverClient(this.EndpointConfigurationName, new EndpointAddress(this.EndpointAddress));
            }
            return(client);
        }
Ejemplo n.º 2
0
        private void Send(NLogEvents events, IEnumerable <AsyncLogEventInfo> asyncContinuations)
        {
            if (!this.OnSend(events, asyncContinuations))
            {
                return;
            }

#if WCF_SUPPORTED
            WcfLogReceiverClient client;

            if (string.IsNullOrEmpty(this.EndpointConfigurationName))
            {
                // endpoint not specified - use BasicHttpBinding
                Binding binding;

#if !SILVERLIGHT2
                if (this.UseBinaryEncoding)
                {
                    binding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new HttpTransportBindingElement());
                }
                else
#endif
                {
                    binding = new BasicHttpBinding();
                }

                client = new WcfLogReceiverClient(binding, new EndpointAddress(this.EndpointAddress));
            }
            else
            {
                client = new WcfLogReceiverClient(this.EndpointConfigurationName, new EndpointAddress(this.EndpointAddress));
            }

            client.ProcessLogMessagesCompleted += (sender, e) =>
            {
                // report error to the callers
                foreach (var ev in asyncContinuations)
                {
                    ev.Continuation(e.Error);
                }

                // send any buffered events
                this.SendBufferedEvents();
            };

            this.inCall = true;
#if SILVERLIGHT
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => client.ProcessLogMessagesAsync(events));
            }
            else
            {
                client.ProcessLogMessagesAsync(events);
            }
#else
            client.ProcessLogMessagesAsync(events);
#endif
#else
            var client = new SoapLogReceiverClient(this.EndpointAddress);
            this.inCall = true;
            client.BeginProcessLogMessages(
                events,
                result =>
            {
                Exception exception = null;

                try
                {
                    client.EndProcessLogMessages(result);
                }
                catch (Exception ex)
                {
                    if (ex.MustBeRethrown())
                    {
                        throw;
                    }

                    exception = ex;
                }

                // report error to the callers
                foreach (var ev in asyncContinuations)
                {
                    ev.Continuation(exception);
                }

                // send any buffered events
                this.SendBufferedEvents();
            },
                null);
#endif
        }