示例#1
0
        // TChannel provides ContractDescription, attr/config|Config object [TChannel,name] provides Binding, provide Address explicitly
        public ConfigurationDuplexChannelFactory(object callbackObject, string endpointConfigurationName, EndpointAddress remoteAddress, Configuration configuration)
            : base(typeof(TChannel))
        {
            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityConstructChannelFactory, TraceUtility.CreateSourceString(this)), ActivityType.Construct);
                }
                if (callbackObject == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackObject");
                }

                if (endpointConfigurationName == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointConfigurationName");
                }

                if (configuration == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("configuration");
                }

                this.CheckAndAssignCallbackInstance(callbackObject);
                this.InitializeEndpoint(endpointConfigurationName, remoteAddress, configuration);
            }
        }
示例#2
0
        IMethodReturnMessage InvokeChannel(IMethodCallMessage methodCall)
        {
            string       activityName = null;
            ActivityType activityType = ActivityType.Unknown;

            if (DiagnosticUtility.ShouldUseActivity)
            {
                if (ServiceModelActivity.Current == null ||
                    ServiceModelActivity.Current.ActivityType != ActivityType.Close)
                {
                    MethodData methodData = this.GetMethodData(methodCall);
                    if (methodData.MethodBase.DeclaringType == typeof(System.ServiceModel.ICommunicationObject) &&
                        methodData.MethodBase.Name.Equals("Close", StringComparison.Ordinal))
                    {
                        activityName = SR.GetString(SR.ActivityClose, this.serviceChannel.GetType().FullName);
                        activityType = ActivityType.Close;
                    }
                }
            }

            using (ServiceModelActivity activity = string.IsNullOrEmpty(activityName) ? null : ServiceModelActivity.CreateBoundedActivity())
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, activityName, activityType);
                }
                return(ExecuteMessage(this.serviceChannel, methodCall));
            }
        }
 private bool ContinueReading(int bytesRead)
 {
     while (true)
     {
         if (bytesRead == 0)
         {
             break;
         }
         this.offset += bytesRead;
         this.count  -= bytesRead;
         if (this.count <= 0)
         {
             break;
         }
         IAsyncResult asyncResult = this.inputStream.BeginRead(this.buffer.Array, this.offset, this.count, onRead, this);
         if (!asyncResult.CompletedSynchronously)
         {
             return(false);
         }
         bytesRead = this.inputStream.EndRead(asyncResult);
     }
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity(true) : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage);
         }
         this.message          = this.httpInput.DecodeBufferedMessage(new ArraySegment <byte>(this.buffer.Array, 0, this.offset), this.inputStream);
         this.requestException = this.httpInput.ProcessHttpAddressing(this.message);
     }
     return(true);
 }
 public IConnection EndAccept(IAsyncResult result)
 {
     using (ServiceModelActivity.BoundOperation(this.activity))
     {
         ServiceModelActivity activity = ServiceModelActivity.CreateActivity();
         if (activity != null)
         {
             if (null != FxTrace.Trace)
             {
                 FxTrace.Trace.TraceTransfer(activity.Id);
             }
         }
         using (ServiceModelActivity.BoundOperation(activity))
         {
             ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityReceiveBytes, this.activity.Name), ActivityType.ReceiveBytes);
             IConnection innerConnection = this.listener.EndAccept(result);
             if (innerConnection == null)
             {
                 return(null);
             }
             TracingConnection retval = new TracingConnection(innerConnection, activity);
             return(retval);
         }
     }
 }
示例#5
0
 internal void ActivityStart(string name)
 {
     using (ServiceModelActivity.BoundOperation(this.activity))
     {
         ServiceModelActivity.Start(this.activity, SR.GetString(SR.ActivityReceiveBytes, name), ActivityType.ReceiveBytes);
     }
 }
        public IConnection EndAccept(IAsyncResult result)
        {
            IConnection connection3;

            using (ServiceModelActivity.BoundOperation(this.activity))
            {
                ServiceModelActivity activity = ServiceModelActivity.CreateActivity();
                if ((activity != null) && (FxTrace.Trace != null))
                {
                    FxTrace.Trace.TraceTransfer(activity.Id);
                }
                using (ServiceModelActivity.BoundOperation(activity))
                {
                    ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityReceiveBytes", new object[] { this.activity.Name }), ActivityType.ReceiveBytes);
                    IConnection connection = this.listener.EndAccept(result);
                    if (connection == null)
                    {
                        return(null);
                    }
                    TracingConnection connection2 = new TracingConnection(connection, activity);
                    connection3 = connection2;
                }
            }
            return(connection3);
        }
示例#7
0
 internal void ActivityStart(Uri uri)
 {
     using (ServiceModelActivity.BoundOperation(this.activity))
     {
         ServiceModelActivity.Start(this.activity, SR.GetString(SR.ActivityReceiveBytes, uri.ToString()), ActivityType.ReceiveBytes);
     }
 }
示例#8
0
 internal void ActivityStart(Uri uri)
 {
     using (ServiceModelActivity.BoundOperation(this.activity))
     {
         ServiceModelActivity.Start(this.activity, System.ServiceModel.SR.GetString("ActivityReceiveBytes", new object[] { uri.ToString() }), ActivityType.ReceiveBytes);
     }
 }
        public virtual TChannel CreateChannel(EndpointAddress address, Uri via)
        {
            TChannel local;
            bool     traceOpenAndClose = base.TraceOpenAndClose;

            try
            {
                using (ServiceModelActivity activity = (DiagnosticUtility.ShouldUseActivity && base.TraceOpenAndClose) ? ServiceModelActivity.CreateBoundedActivity() : null)
                {
                    if (DiagnosticUtility.ShouldUseActivity)
                    {
                        ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType);
                        base.TraceOpenAndClose = false;
                    }
                    if (address == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
                    }
                    if (base.HasDuplexOperations())
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCreateNonDuplexChannel1", new object[] { base.Endpoint.Contract.Name })));
                    }
                    base.EnsureOpened();
                    local = (TChannel)this.ServiceChannelFactory.CreateChannel(typeof(TChannel), address, via);
                }
            }
            finally
            {
                base.TraceOpenAndClose = traceOpenAndClose;
            }
            return(local);
        }
        int WbemNative.IWbemServices.PutInstanceAsync(
            WbemNative.IWbemClassObject wbemObject,
            Int32 lFlags,
            WbemNative.IWbemContext wbemContext,
            WbemNative.IWbemObjectSink wbemSink
            )
        {
            if (wbemObject == null || wbemContext == null || wbemSink == null || this.wbemServices == null)
            {
                return((int)WbemNative.WbemStatus.WBEM_E_INVALID_PARAMETER);
            }

            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                try
                {
                    object val   = null;
                    int    type  = 0;
                    int    favor = 0;
                    WbemException.ThrowIfFail(wbemObject.Get("__CLASS", 0, ref val, ref type, ref favor));
                    string className = (string)val;
                    ServiceModelActivity.Start(activity, SR.GetString(SR.WmiPutInstance, string.IsNullOrEmpty(className) ? string.Empty : className), ActivityType.WmiPutInstance);

                    ParameterContext parms        = new ParameterContext(className, this.wbemServices, wbemContext, wbemSink);
                    WbemInstance     wbemInstance = new WbemInstance(parms, wbemObject);
                    IWmiProvider     wmiProvider  = this.GetProvider(parms.ClassName);
                    if (wmiProvider.PutInstance(new InstanceContext(wbemInstance)))
                    {
                        wbemInstance.Indicate();
                    }

                    WbemException.ThrowIfFail(wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                                                 (int)WbemNative.WbemStatus.WBEM_S_NO_ERROR, null, null));
                }
                catch (WbemException e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       e.ErrorCode, null, null);
                    return(e.ErrorCode);
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error, (ushort)System.Runtime.Diagnostics.EventLogCategory.Wmi, (uint)System.Runtime.Diagnostics.EventLogEventId.WmiPutInstanceFailed,
                                                        TraceUtility.CreateSourceString(this), e.ToString());
                    wbemSink.SetStatus((int)WbemNative.tag_WBEM_STATUS_TYPE.WBEM_STATUS_COMPLETE,
                                       (int)WbemNative.WbemStatus.WBEM_E_FAILED, null, null);
                    return((int)WbemNative.WbemStatus.WBEM_E_FAILED);
                }
                finally
                {
                    Marshal.ReleaseComObject(wbemSink);
                }
            }
            return((int)WbemNative.WbemStatus.WBEM_S_NO_ERROR);
        }
        public Message ParseIncomingMessage(out Exception requestException)
        {
            Message message = null;
            Message message2;

            requestException = null;
            bool flag = true;

            try
            {
                this.ValidateContentType();
                ServiceModelActivity activity = null;
                if (DiagnosticUtility.ShouldUseActivity && ((ServiceModelActivity.Current == null) || (ServiceModelActivity.Current.ActivityType != ActivityType.ProcessAction)))
                {
                    activity = ServiceModelActivity.CreateBoundedActivity(true);
                }
                using (activity)
                {
                    if (DiagnosticUtility.ShouldUseActivity && (activity != null))
                    {
                        ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage);
                    }
                    if (!this.HasContent)
                    {
                        if (this.messageEncoder.MessageVersion != MessageVersion.None)
                        {
                            return(null);
                        }
                        message = new NullMessage();
                    }
                    else if (this.streamed)
                    {
                        message = this.ReadStreamedMessage(this.InputStream);
                    }
                    else if (this.ContentLength == -1L)
                    {
                        message = this.ReadChunkedBufferedMessage(this.InputStream);
                    }
                    else
                    {
                        message = this.ReadBufferedMessage(this.InputStream);
                    }
                    requestException = this.ProcessHttpAddressing(message);
                    flag             = false;
                    message2         = message;
                }
            }
            finally
            {
                if (flag)
                {
                    this.Close();
                }
            }
            return(message2);
        }
示例#12
0
 public void Open(TimeSpan timeout)
 {
     if (timeout < TimeSpan.Zero)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("timeout", System.ServiceModel.SR.GetString("SFxTimeoutOutOfRange0")));
     }
     if (TD.CommunicationObjectOpenStartIsEnabled())
     {
         TD.CommunicationObjectOpenStart();
     }
     using (ServiceModelActivity activity = (DiagnosticUtility.ShouldUseActivity && this.TraceOpenAndClose) ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType);
         }
         lock (this.ThisLock)
         {
             this.ThrowIfDisposedOrImmutable();
             this.state = CommunicationState.Opening;
         }
         bool flag = true;
         try
         {
             TimeoutHelper helper = new TimeoutHelper(timeout);
             this.OnOpening();
             if (!this.onOpeningCalled)
             {
                 throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpening"), Guid.Empty, this);
             }
             this.OnOpen(helper.RemainingTime());
             this.OnOpened();
             if (!this.onOpenedCalled)
             {
                 throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpened"), Guid.Empty, this);
             }
             flag = false;
         }
         finally
         {
             if (flag)
             {
                 if (DiagnosticUtility.ShouldTraceWarning)
                 {
                     TraceUtility.TraceEvent(TraceEventType.Warning, 0x80005, System.ServiceModel.SR.GetString("TraceCodeCommunicationObjectOpenFailed", new object[] { this.GetCommunicationObjectType().ToString() }), this);
                 }
                 this.Fault();
             }
         }
     }
     if (TD.CommunicationObjectOpenStopIsEnabled())
     {
         TD.CommunicationObjectOpenStop();
     }
 }
示例#13
0
        public void Open(TimeSpan timeout)
        {
            if (timeout < TimeSpan.Zero)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ArgumentOutOfRangeException("timeout", SR.GetString(SR.SFxTimeoutOutOfRange0)));
            }

            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity && this.TraceOpenAndClose ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, this.OpenActivityName, this.OpenActivityType);
                }
                lock (ThisLock)
                {
                    ThrowIfDisposedOrImmutable();
                    this.state = CommunicationState.Opening;
                }

                bool throwing = true;
                try
                {
                    TimeoutHelper actualTimeout = new TimeoutHelper(timeout);

                    OnOpening();
                    if (!this.onOpeningCalled)
                    {
                        throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpening"), Guid.Empty, this);
                    }

                    OnOpen(actualTimeout.RemainingTime());

                    OnOpened();
                    if (!this.onOpenedCalled)
                    {
                        throw TraceUtility.ThrowHelperError(this.CreateBaseClassMethodNotCalledException("OnOpened"), Guid.Empty, this);
                    }

                    throwing = false;
                }
                finally
                {
                    if (throwing)
                    {
                        if (DiagnosticUtility.ShouldTraceWarning)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.CommunicationObjectOpenFailed, SR.GetString(SR.TraceCodeCommunicationObjectOpenFailed, this.GetCommunicationObjectType().ToString()), this);
                        }

                        Fault();
                    }
                }
            }
        }
        private ServiceModelActivity CreateCloseActivity()
        {
            ServiceModelActivity serviceModelActivity = null;

            serviceModelActivity = ServiceModelActivity.CreateBoundedActivity();
            if (Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldUseActivity)
            {
                ServiceModelActivity.Start(serviceModelActivity, this.CloseActivityName, ActivityType.Close);
            }
            return(serviceModelActivity);
        }
示例#15
0
        private ServiceModelActivity CreateCloseActivity()
        {
            ServiceModelActivity activity = null;

            activity = ServiceModelActivity.CreateBoundedActivity();
            if (DiagnosticUtility.ShouldUseActivity)
            {
                ServiceModelActivity.Start(activity, this.CloseActivityName, ActivityType.Close);
            }
            return(activity);
        }
示例#16
0
        public static ServiceModelActivity BoundReceiveBytesOperation()
        {
            ServiceModelActivity activity = null;

            if (DiagnosticUtility.ShouldUseActivity)
            {
                activity = ServiceModelActivity.CreateBoundedActivityWithTransferInOnly(Guid.NewGuid());
                ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityReceiveBytes", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ReceiveBytes);
            }
            return(activity);
        }
示例#17
0
        public static ServiceModelActivity BoundDecodeOperation()
        {
            ServiceModelActivity activity = null;

            if (DiagnosticUtility.ShouldUseActivity)
            {
                activity = ServiceModelActivity.CreateBoundedActivity(true);
                ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage);
            }
            return(activity);
        }
 public ChannelFactory() : this(typeof(TChannel))
 {
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructChannelFactory", new object[] { typeof(TChannel).FullName }), ActivityType.Construct);
         }
         base.InitializeEndpoint((string)null, null);
     }
 }
示例#19
0
        ServiceModelActivity CreateCloseActivity()
        {
            ServiceModelActivity retval = null;

            retval = ServiceModelActivity.CreateBoundedActivity();
            if (DiagnosticUtility.ShouldUseActivity)
            {
                ServiceModelActivity.Start(retval, this.CloseActivityName, ActivityType.Close);
            }

            return(retval);
        }
示例#20
0
        public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
        {
            ServiceModelActivity activity = receiver.Activity;

            if (DiagnosticUtility.ShouldUseActivity && (activity == null))
            {
                activity = ServiceModelActivity.CreateActivity(true);
                if (FxTrace.Trace != null)
                {
                    FxTrace.Trace.TraceTransfer(activity.Id);
                }
                ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityListenAt", new object[] { receiver.ListenUri.ToString() }), ActivityType.ListenAt);
            }
            return(activity);
        }
 public ChannelFactory(string endpointConfigurationName, EndpointAddress remoteAddress) : this(typeof(TChannel))
 {
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructChannelFactory", new object[] { typeof(TChannel).FullName }), ActivityType.Construct);
         }
         if (endpointConfigurationName == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointConfigurationName");
         }
         base.InitializeEndpoint(endpointConfigurationName, remoteAddress);
     }
 }
        public static ServiceModelActivity StartListenAtActivity(MsmqReceiveHelper receiver)
        {
            ServiceModelActivity activity = receiver.Activity;

            if (DiagnosticUtility.ShouldUseActivity && null == activity)
            {
                activity = ServiceModelActivity.CreateActivity(true);
                if (null != FxTrace.Trace)
                {
                    FxTrace.Trace.TraceTransfer(activity.Id);
                }
                ServiceModelActivity.Start(activity, SR.GetString(SR.ActivityListenAt, receiver.ListenUri.ToString()), ActivityType.ListenAt);
            }
            return(activity);
        }
 public ServiceHost(System.Type serviceType, params Uri[] baseAddresses)
 {
     if (serviceType == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceType"));
     }
     this.serviceType = serviceType;
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructServiceHost", new object[] { serviceType.FullName }), ActivityType.Construct);
         }
         this.InitializeDescription(serviceType, new UriSchemeKeyedCollection(baseAddresses));
     }
 }
 public DuplexChannelFactory(object callbackObject) : base(typeof(TChannel))
 {
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructChannelFactory", new object[] { TraceUtility.CreateSourceString(this) }), ActivityType.Construct);
         }
         if (callbackObject == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("callbackObject");
         }
         this.CheckAndAssignCallbackInstance(callbackObject);
         base.InitializeEndpoint((string)null, null);
     }
 }
        private static IDisposable CreateProcessActionActivity()
        {
            IDisposable disposable = null;

            if (!DiagnosticUtility.ShouldUseActivity || ((ServiceModelActivity.Current != null) && (ServiceModelActivity.Current.ActivityType == ActivityType.ProcessAction)))
            {
                return(disposable);
            }
            if (((ServiceModelActivity.Current != null) && (ServiceModelActivity.Current.PreviousActivity != null)) && (ServiceModelActivity.Current.PreviousActivity.ActivityType == ActivityType.ProcessAction))
            {
                return(ServiceModelActivity.BoundOperation(ServiceModelActivity.Current.PreviousActivity));
            }
            ServiceModelActivity activity = ServiceModelActivity.CreateBoundedActivity(true);

            ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityProcessingMessage", new object[] { TraceUtility.RetrieveMessageNumber() }), ActivityType.ProcessMessage);
            return(activity);
        }
 public ServiceHost(object singletonInstance, params Uri[] baseAddresses)
 {
     if (singletonInstance == null)
     {
         throw new ArgumentNullException("singletonInstance");
     }
     this.singletonInstance = singletonInstance;
     this.serviceType       = singletonInstance.GetType();
     using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity.Start(activity, System.ServiceModel.SR.GetString("ActivityConstructServiceHost", new object[] { this.serviceType.FullName }), ActivityType.Construct);
         }
         this.InitializeDescription(singletonInstance, new UriSchemeKeyedCollection(baseAddresses));
     }
 }
示例#27
0
        void ICommunicationObject.Close(TimeSpan timeout)
        {
            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, SR.Format(SR.ActivityCloseClientBase, typeof(TChannel).FullName), ActivityType.Close);
                }

                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                if (_channel != null)
                {
                    InnerChannel.Close(timeoutHelper.RemainingTime());
                }

                if (!_channelFactoryRefReleased)
                {
                    lock (s_staticLock)
                    {
                        if (!_channelFactoryRefReleased)
                        {
                            if (_channelFactoryRef.Release())
                            {
                                _releasedLastRef = true;
                            }

                            _channelFactoryRefReleased = true;
                        }
                    }

                    // Close the factory outside of the lock so that we can abort from a different thread.
                    if (_releasedLastRef)
                    {
                        if (_useCachedFactory)
                        {
                            _channelFactoryRef.Abort();
                        }
                        else
                        {
                            _channelFactoryRef.Close(timeoutHelper.RemainingTime());
                        }
                    }
                }
            }
        }
示例#28
0
        internal void Open(TransportChannelListener channelListener)
        {
            if (DiagnosticUtility.ShouldUseActivity)
            {
                if (this.activity == null)
                {
                    this.activity = ServiceModelActivity.CreateActivity(true);
                    if (DiagnosticUtility.ShouldUseActivity)
                    {
                        if (null != FxTrace.Trace)
                        {
                            FxTrace.Trace.TraceTransfer(this.Activity.Id);
                        }
                        ServiceModelActivity.Start(this.Activity, SR.GetString(SR.ActivityListenAt, channelListener.Uri.ToString()), ActivityType.ListenAt);
                    }
                }
                channelListener.Activity = this.Activity;
            }
            using (ServiceModelActivity.BoundOperation(this.Activity))
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.TransportListen,
                                            SR.GetString(SR.TraceCodeTransportListen, channelListener.Uri.ToString()), this);
                }
                this.Register(channelListener);
                try
                {
                    lock (ThisLock)
                    {
                        if (openCount == 0)
                        {
                            OnOpen();
                        }

                        openCount++;
                    }
                }
                catch
                {
                    this.Unregister(channelListener);
                    throw;
                }
            }
        }
示例#29
0
        void ICommunicationObject.Close(TimeSpan timeout)
        {
            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, SR.Format(SR.ActivityCloseClientBase, typeof(TChannel).FullName), ActivityType.Close);
                }
                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

                if (_channel != null)
                {
                    InnerChannel.Close(timeoutHelper.RemainingTime());
                }

                ChannelFactory.Close(timeoutHelper.RemainingTime());
            }
        }
        // TChannel provides ContractDescription
        public DuplexChannelFactory(object callbackObject)
            : base(typeof(TChannel))
        {
            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null)
            {
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    ServiceModelActivity.Start(activity, SR.Format(SR.ActivityConstructChannelFactory, TraceUtility.CreateSourceString(this)), ActivityType.Construct);
                }
                if (callbackObject == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(callbackObject));
                }

                CheckAndAssignCallbackInstance(callbackObject);
                InitializeEndpoint((string)null, (EndpointAddress)null);
            }
        }