private static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); Action <Task <object>, object> completeCallDelegate = (antecedent, obj) => { var tcsObj = obj as TaskCompletionSource <object>; Contract.Assert(tcsObj != null); if (antecedent.IsFaulted) { tcsObj.TrySetException(antecedent.Exception.InnerException); } else if (antecedent.IsCanceled) { tcsObj.TrySetCanceled(); } else { tcsObj.TrySetResult(antecedent.Result); } }; try { channel.CallAsync(operation.Action, operation.IsOneWay, operation, inputParameters, Array.Empty <object>()).ContinueWith(completeCallDelegate, tcs); } catch (Exception e) { tcs.TrySetException(e); } return(tcs.Task); }
void InputSessionFaultedCore(ServiceChannel channel) { IDuplexContextChannel proxy = channel.Proxy as IDuplexContextChannel; if (proxy != null) { IInputSessionShutdown[] handlers = inputSessionShutdownHandlers; try { for (int i = 0; i < handlers.Length; i++) { handlers[i].ChannelFaulted(proxy); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!error.HandleError(e)) { proxy.Abort(); } } } }
internal void InputSessionDoneReceiving(ServiceChannel channel) { if (inputSessionShutdownHandlers.Length > 0) { InputSessionDoneReceivingCore(channel); } }
protected async override Task Send(ServiceChannel serviceChannel, string message) { var channel = client.GetChannel((ulong)serviceChannel.Id); if (channel is ITextChannel ichannel) { await ichannel.SendMessageAsync(message); //var splitName = serviceChannel.Name.Split('#'); //if (splitName.Length != 2) //{ // return; //} //var user = client.GetUser(splitName[0].Substring(1), splitName[1]); //if (user != null) //{ // var dmchannel = user.GetOrCreateDMChannelAsync().Result; // await dmchannel.SendMessageAsync(message); //} } else if (channel is IDMChannel dmChannel) { dmChannel.SendMessageAsync(message); } //else if (channel is SocketTextChannel textChannel) //{ // await textChannel.SendMessageAsync(message); //} //throw new NotImplementedException(); }
internal void InputSessionFaulted(ServiceChannel channel) { if (inputSessionShutdownHandlers.Length > 0) { InputSessionFaultedCore(channel); } }
public void ServiceChannel060Test() { var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); using (var stream1 = new MemoryStream()) using (var stream2 = new MemoryStream()) using (var clientChannel = new ServiceChannel()) using (var serviceChannel = new ServiceChannel()) { serviceChannel.SetReadStream(stream1, false); //serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key"); clientChannel.SetWriteStream(stream2, false); clientChannel.Encrypt(); clientChannel.WriteObject("HELO"); clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem"); clientChannel.Encrypt(); clientChannel.WriteObject("HELO2"); clientChannel.Flush(); Console.WriteLine(stream2.Length); TransferData(stream2, stream1); var msg = serviceChannel.ReadObject <string>(); Assert.AreEqual("HELO", msg); Assert.Catch <SecureChannelException>(() => { var msg2 = serviceChannel.ReadObject <string>(); }); } }
internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceChannel channel) { ClientRuntime clientRuntime = channel.ClientRuntime; this.messageVersion = messageVersion; this.isManualAddressing = clientRuntime.ManualAddressing; this.binder = binder; this.channel = channel; this.isConcurrent = true; this.duplexBinder = binder as DuplexChannelBinder; this.hasSession = binder.HasSession; this.isCallback = true; DispatchRuntime dispatchRuntime = clientRuntime.DispatchRuntime; if (dispatchRuntime == null) { this.receiver = new ErrorHandlingReceiver(binder, null); } else { this.receiver = new ErrorHandlingReceiver(binder, dispatchRuntime.ChannelDispatcher); } this.requestInfo = new RequestInfo(this); }
public void ServiceChannel070Test() { var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); using (var stream1 = new MemoryStream()) using (var stream2 = new MemoryStream()) using (var clientChannel = new ServiceChannel()) using (var serviceChannel = new ServiceChannel()) { serviceChannel.SetReadStream(stream1, false); serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key"); clientChannel.SetWriteStream(stream2, false); clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem"); clientChannel.Encrypt(); var data = Security.Random.Get(128 * 1024 + 1); clientChannel.Encrypt(); clientChannel.Write(data); clientChannel.Flush(); Console.WriteLine(stream2.Length); TransferData(stream2, stream1); var data1 = serviceChannel.Read(); Assert.AreEqual(Hash.MD5(data), Hash.MD5(data1)); } }
private ServiceChannel GetSessionChannel(Message message, out EndpointDispatcher endpoint, out bool addressMatched) { addressMatched = false; if (_channel == null) { lock (ThisLock) { if (_channel == null) { endpoint = GetEndpointDispatcher(message, out addressMatched); if (endpoint != null) { _channel = new ServiceChannel(_binder, endpoint, _serviceDispatcher, _idleManager.UseIfNeeded(_binder, _serviceDispatcher.Binding.ReceiveTimeout)); InitializeServiceChannel(_channel); } } } } if (_channel == null) { endpoint = null; } else { endpoint = _channel.EndpointDispatcher; } return(_channel); }
public void Apply(SettingsContract settings) { using (ServiceChannel <ISettingsContract> channel = _channelFactory.Create <ISettingsContract>(Endpoint)) { channel.Proxy.Apply(settings); } }
private void InputSessionDoneReceivingCore(ServiceChannel channel) { if (channel.Proxy is IDuplexContextChannel proxy) { IInputSessionShutdown[] handlers = _inputSessionShutdownHandlers; try { for (int i = 0; i < handlers.Length; i++) { handlers[i].DoneReceiving(proxy); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!ErrorBehavior.HandleError(e)) { proxy.Abort(); } } } }
private static Task CreateGenericTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { TaskCompletionSourceProxy tcsp = new TaskCompletionSourceProxy(operation.TaskTResult); Action <Task <object>, object> completeCallDelegate = (antecedent, obj) => { var tcsProxy = obj as TaskCompletionSourceProxy; Contract.Assert(tcsProxy != null); if (antecedent.IsFaulted) { tcsProxy.TrySetException(antecedent.Exception.InnerException); } else if (antecedent.IsCanceled) { tcsProxy.TrySetCanceled(); } else { tcsProxy.TrySetResult(antecedent.Result); } }; try { channel.CallAsync(operation.Action, operation.IsOneWay, operation, inputParameters, Array.Empty <object>()).ContinueWith(completeCallDelegate, tcsp); } #pragma warning disable CA1031 // Do not catch general exception types - copying all exceptions to TaskCompeletionSource catch (Exception e) { tcsp.TrySetException(e); } #pragma warning restore CA1031 // Do not catch general exception types return(tcsp.Task); }
internal OperationContext(RequestContext requestContext, Message request, ServiceChannel channel) { _channel = channel; _requestContext = requestContext; _request = request; _outgoingMessageVersion = channel.MessageVersion; }
internal void BeforeSendRequest(ref ProxyRpc rpc) { int offset = this.MessageInspectorCorrelationOffset; try { for (int i = 0; i < _messageInspectors.Length; i++) { ServiceChannel clientChannel = ServiceChannelFactory.GetServiceChannel(rpc.Channel.Proxy); rpc.Correlation[offset + i] = _messageInspectors[i].BeforeSendRequest(ref rpc.Request, clientChannel); if (WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvokedIsEnabled()) { WcfEventSource.Instance.ClientMessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, _messageInspectors[i].GetType().FullName); } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e); } }
internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceChannel channel) { ClientRuntime clientRuntime = channel.ClientRuntime; _messageVersion = messageVersion; _isManualAddressing = clientRuntime.ManualAddressing; _binder = binder; _channel = channel; _isConcurrent = true; _duplexBinder = binder as DuplexChannelBinder; _hasSession = binder.HasSession; _isCallback = true; DispatchRuntime dispatchRuntime = clientRuntime.DispatchRuntime; if (dispatchRuntime == null) { _receiver = new ErrorHandlingReceiver(binder, null); } else { _receiver = new ErrorHandlingReceiver(binder, dispatchRuntime.ChannelDispatcher); } _requestInfo = new RequestInfo(this); }
private ServiceChannel GetSessionChannel(Message message, out EndpointDispatcher endpoint, out bool addressMatched) { addressMatched = false; if (_channel == null) { lock (this.ThisLock) { if (_channel == null) { endpoint = this.GetEndpointDispatcher(message, out addressMatched); if (endpoint != null) { _channel = new ServiceChannel(_binder, endpoint, _listener.ChannelDispatcher, _idleManager); this.InitializeServiceChannel(_channel); } } } } if (_channel == null) { endpoint = null; } else { endpoint = _channel.EndpointDispatcher; } return(_channel); }
private int _ledState = 0; // LED state #region DeviceBase Members /// <summary> /// Represents main device thread. /// </summary> /// <param name="token">Thread cancellation token.</param> public override void Main(CancellationToken token) { // send the notification about initial LED state ServiceChannel.SendEquipmentNotification(LED_CODE, new LedNotification(_ledState)); // do nothing in the main thread }
public OperationContext(IContextChannel channel) { if (channel == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("channel")); } ServiceChannel serviceChannel = channel as ServiceChannel; //Could be a TransparentProxy if (serviceChannel == null) { serviceChannel = ServiceChannelFactory.GetServiceChannel(channel); } if (serviceChannel != null) { this.outgoingMessageVersion = serviceChannel.MessageVersion; this.channel = serviceChannel; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInvalidChannelToOperationContext))); } }
public void Audit(AuditEvent auditEvent) { decimal sessionID = Convert.ToDecimal(Nucleo.Common.Security.SecurityManager.CurrentUser.NucleoIdentity.SessionId);//(decimal)(Nucleo.Shared.DataHolder.GetValue(ClaimNames.SessionID.ToString()) ?? -1m); decimal fichaID = (decimal)(Nucleo.Shared.DataHolder.GetValue(ClaimNames.FichaID.ToString()) ?? -1m); decimal episodioID = (decimal)(Nucleo.Shared.DataHolder.GetValue(ClaimNames.EpisodioID.ToString()) ?? -1m); decimal encuentroID = (decimal)(Nucleo.Shared.DataHolder.GetValue(ClaimNames.EncuentroID.ToString()) ?? -1m); if (auditEvent.Context.ContainsKey(ClaimEventType.ModuleUsageStartAuditing.ToString())) { if (auditEvent.EventText.Contains("Container")) { return; } if (auditEvent.EventText.Contains("ReportViewer")) { return; } var client = new WsauditoriagestionWebClient(); using (ServiceChannel.AsDisposable(client)) { var res = client.fcespIniciaAuditoriaAsync(auditEvent.EventText, sessionID, fichaID, episodioID, encuentroID); } } }
/// <summary> /// Crée un fichier Excel 2003 à partir des valeurs et des critères données. /// </summary> /// <param name="exportData">Données de l'export.</param> /// <returns>Le fichier Excel généré.</returns> public static byte[] CreateXlsDocument(ExportDataSource exportData) { byte[] xlsxDocument = CreateXslsxDocument(exportData); using (ServiceChannel <IExcelConverter> channel = new ServiceChannel <IExcelConverter>()) { return(channel.Service.XlsxToXls(xlsxDocument)); } }
public void DbxGetKeyCommandTest020() { using (var stream1 = new MemoryStream()) using (var channel1 = new ServiceChannel()) using (var channel2 = new ServiceChannel()) { channel1.SetWriteStream(stream1, canDispose: false); Context ctx = new Context(); ctx.ClientIP = IPAddress.None; ctx.Channel = channel1; ctx.Query = new QueryMessage { Command = "dbx-GetKey" }; ctx.Query.Params["username"] = "******"; ctx.Query.Params["uuid"] = "safevault"; ctx.Query.Params["password"] = OneTimePassword.Get(Base32.Decode("12345678"), 0); Command.Process(ctx); stream1.Position = 0; channel2.SetReadStream(stream1, canDispose: false); Assert.Catch <SecureChannelException>(() => channel2.ReadObject <ResponseMessage>()); } }
public void DbxGetKeyCommandTest010() { using (var stream1 = new MemoryStream()) using (var channel1 = new ServiceChannel()) using (var channel2 = new ServiceChannel()) { channel1.SetWriteStream(stream1, canDispose: false); Context ctx = new Context(); ctx.ClientIP = IPAddress.None; ctx.Channel = channel1; ctx.Query = new QueryMessage { Command = "dbx-GetKey" }; ctx.Query.Params["username"] = "******"; ctx.Query.Params["uuid"] = "safevault"; ctx.Query.Params["password"] = OneTimePassword.Get(Base32.Decode("12345678"), 0); Command.Process(ctx); stream1.Position = 0; channel2.SetReadStream(stream1, canDispose: false); channel2.CipherLib["rsa-private"] = RsaCipher .LoadFromPEM($"{_location}/data/client/test-user/cer.pem", $"{_location}/data/client/test-user/cer.pem.key"); var response = channel2.ReadObject <ResponseMessage>(); Assert.AreEqual(200, response.StatusCode); var data = response.Header["data"]; Assert.AreEqual("1234567801234567890abcdefghiklmnopqvwxyz12345678012345678901234567890=", data); } }
public static void Add(News news) { ServiceChannel.Save(news); lock (C_News) { C_News = ServiceChannel.FindAllNews().ToList(); } }
internal OperationContext(RequestContext requestContext, Message request, ServiceChannel channel, ServiceHostBase host) { this.channel = channel; this.host = host; this.requestContext = requestContext; this.request = request; this.outgoingMessageVersion = channel.MessageVersion; }
public void Cleanup() { this.Endpoint = null; this.ExistingInstanceContext = null; this.Channel = null; this.EndpointLookupDone = false; this.RequestContext = null; }
public void Cleanup() { Endpoint = null; ExistingInstanceContext = null; Channel = null; EndpointLookupDone = false; RequestContext = null; }
public static Task CreateTask(ServiceChannel channel, MethodCall methodCall, ProxyOperationRuntime operation) { if (operation.TaskTResult == ServiceReflector.VoidType) { return(CreateTask(channel, operation, methodCall.Args)); } return(CreateGenericTask(channel, operation, methodCall.Args)); }
internal OperationContext(RequestContext requestContext, Message request, ServiceChannel channel, ServiceHostBase host) { InternalServiceChannel = channel; Host = host; RequestContext = requestContext; _request = request; OutgoingMessageVersion = channel.MessageVersion; }
internal DisplayInitializationUIAsyncResult(ServiceChannel channel, IInteractiveChannelInitializer[] initializers, AsyncCallback callback, object state) : base(callback, state) { this.index = -1; this.channel = channel; this.initializers = initializers; this.proxy = channel.Proxy as IClientChannel; this.CallBegin(true); }
public Task <object> InvokeAsync(object instance, object[] inputs, out object[] outputs) { outputs = EmptyArray <object> .Allocate(0); Message message = inputs[0] as Message; if (message == null) { return(null); } string action = message.Headers.Action; FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported, message.Version.Addressing.Namespace); string reasonText = SR.Format(SR.SFxNoEndpointMatchingContract, action); FaultReason reason = new FaultReason(reasonText); FaultException exception = new FaultException(reason, code); ErrorBehavior.ThrowAndCatch(exception); ServiceChannel serviceChannel = OperationContext.Current.InternalServiceChannel; OperationContext.Current.OperationCompleted += delegate(object sender, EventArgs e) { ChannelDispatcher channelDispatcher = _dispatchRuntime.ChannelDispatcher; if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession) { try { serviceChannel.Close(ChannelHandler.CloseAfterFaultTimeout); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } channelDispatcher.HandleError(ex); } } }; if (_dispatchRuntime._shared.EnableFaults) { MessageFault fault = MessageFault.CreateFault(code, reason, action); return(Task.FromResult((object)Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction))); } else { OperationContext.Current.RequestContext.Close(); OperationContext.Current.RequestContext = null; return(Task.FromResult((object)null)); } }
public override void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel channel) { ServiceChannel serviceChannel = GetServiceChannelFromProxy(channel); if (serviceChannel != null && serviceChannel.HasSession) { instanceContext.BindIncomingChannel(serviceChannel); } }
internal ServiceChannelProxy(System.Type interfaceType, System.Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel) : base(proxiedType) { if (!MessageDirectionHelper.IsDefined(direction)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("direction")); } this.interfaceType = interfaceType; this.proxiedType = proxiedType; this.serviceChannel = serviceChannel; this.proxyRuntime = serviceChannel.ClientRuntime.GetRuntime(); this.methodDataCache = new MethodDataCache(); this.objectWrapper = new MbrObject(this, proxiedType); }
public ServiceChannel[] GetChannels() { List<ServiceChannel> list = new List<ServiceChannel>(); foreach (var type in Builder.EntityTypes) { Type instance = typeof(CacheEntityQueryable<>).MakeGenericType(new Type[] { type }); Type contract = typeof(ICacheEntityQueryable<>).MakeGenericType(new Type[] { type }); ServiceProvider provider = new ServiceProvider(instance, contract); ServiceChannel channel = new ServiceChannel("Comboost_EntityChannel_" + type.Name, provider, DataFormatter); list.Add(channel); } return list.ToArray(); }
internal ProxyRpc(ServiceChannel channel, ProxyOperationRuntime operation, string action, object[] inputs, TimeSpan timeout) { this.Action = action; this.Activity = null; this.Channel = channel; this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount); this.InputParameters = inputs; this.Operation = operation; this.OutputParameters = null; this.Request = null; this.Reply = null; this.ActivityId = Guid.Empty; this.ReturnValue = null; this.MessageVersion = channel.MessageVersion; this.TimeoutHelper = new System.Runtime.TimeoutHelper(timeout); }
private ServiceChannel CreateChannel() { Thread.MemoryBarrier(); if (this.serviceChannel == null) { lock (this) { Thread.MemoryBarrier(); if (this.serviceChannel == null) { try { if (this.serviceChannelFactory == null) { this.FaultInserviceChannelFactory(); } if (this.serviceChannelFactory == null) { throw Fx.AssertAndThrow("ServiceChannelFactory cannot be null at this point"); } this.serviceChannelFactory.Open(); if (this.serviceEndpoint == null) { throw Fx.AssertAndThrow("ServiceEndpoint cannot be null"); } this.serviceChannel = this.serviceChannelFactory.CreateServiceChannel(new EndpointAddress(this.serviceEndpoint.Address.Uri, this.serviceEndpoint.Address.Identity, this.serviceEndpoint.Address.Headers), this.serviceEndpoint.Address.Uri); ComPlusChannelCreatedTrace.Trace(TraceEventType.Verbose, 0x5001f, "TraceCodeComIntegrationChannelCreated", this.serviceEndpoint.Address.Uri, this.contractDescription.ContractType); if (this.serviceChannel == null) { throw Fx.AssertAndThrow("serviceProxy MUST derive from RealProxy"); } } finally { if ((this.serviceChannel == null) && (this.serviceChannelFactory != null)) { this.serviceChannelFactory.Close(); } } } } } return this.serviceChannel; }
internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceThrottle throttle, ListenerHandler listener, bool wasChannelThrottled, WrappedTransaction acceptTransaction, ServiceChannel.SessionIdleManager idleManager) { ChannelDispatcher channelDispatcher = listener.ChannelDispatcher; this.messageVersion = messageVersion; this.isManualAddressing = channelDispatcher.ManualAddressing; this.binder = binder; this.throttle = throttle; this.listener = listener; this.wasChannelThrottled = wasChannelThrottled; this.host = listener.Host; this.receiveSynchronously = channelDispatcher.ReceiveSynchronously; this.duplexBinder = binder as DuplexChannelBinder; this.hasSession = binder.HasSession; this.isConcurrent = ConcurrencyBehavior.IsConcurrent(channelDispatcher, this.hasSession); if (channelDispatcher.MaxPendingReceives > 1) { this.binder = new MultipleReceiveBinder(this.binder, channelDispatcher.MaxPendingReceives, !this.isConcurrent); } if (channelDispatcher.BufferedReceiveEnabled) { this.binder = new BufferedReceiveBinder(this.binder); } this.receiver = new ErrorHandlingReceiver(this.binder, channelDispatcher); this.idleManager = idleManager; if (!channelDispatcher.IsTransactedReceive || channelDispatcher.ReceiveContextEnabled) { if ((channelDispatcher.IsTransactedReceive && channelDispatcher.ReceiveContextEnabled) && (channelDispatcher.MaxTransactedBatchSize > 0)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("IncompatibleBehaviors"))); } } else { this.receiveSynchronously = true; this.receiveWithTransaction = true; if (channelDispatcher.MaxTransactedBatchSize > 0) { int maxConcurrentBatches = 1; if ((throttle != null) && (throttle.MaxConcurrentCalls > 1)) { maxConcurrentBatches = throttle.MaxConcurrentCalls; foreach (EndpointDispatcher dispatcher2 in channelDispatcher.Endpoints) { if (ConcurrencyMode.Multiple != dispatcher2.DispatchRuntime.ConcurrencyMode) { maxConcurrentBatches = 1; break; } } } this.sharedTransactedBatchContext = new SharedTransactedBatchContext(this, channelDispatcher, maxConcurrentBatches); this.isMainTransactedBatchHandler = true; this.throttle = null; } } this.acceptTransaction = acceptTransaction; this.requestInfo = new RequestInfo(this); if (!this.hasSession && (this.listener.State == CommunicationState.Opened)) { this.listener.ChannelDispatcher.Channels.IncrementActivityCount(); this.incrementedActivityCountInConstructor = true; } }
ServiceChannel CreateChannel() { if (serviceChannel == null) { lock (this) { if (serviceChannel == null) { try { if (serviceChannelFactory == null) { FaultInserviceChannelFactory(); } if (serviceChannelFactory == null) { throw Fx.AssertAndThrow("ServiceChannelFactory cannot be null at this point"); } serviceChannelFactory.Open(); if (serviceEndpoint == null) { throw Fx.AssertAndThrow("ServiceEndpoint cannot be null"); } ServiceChannel localChannel = serviceChannelFactory.CreateServiceChannel(new EndpointAddress(serviceEndpoint.Address.Uri, serviceEndpoint.Address.Identity, serviceEndpoint.Address.Headers), serviceEndpoint.Address.Uri); serviceChannel = localChannel; ComPlusChannelCreatedTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationChannelCreated, SR.TraceCodeComIntegrationChannelCreated, serviceEndpoint.Address.Uri, contractDescription.ContractType); if (serviceChannel == null) { throw Fx.AssertAndThrow("serviceProxy MUST derive from RealProxy"); } } finally { if ((serviceChannel == null) && (serviceChannelFactory != null)) { serviceChannelFactory.Close(); } } } } } return serviceChannel; }
internal DisplayInitializationUIAsyncResult(ServiceChannel channel, IInteractiveChannelInitializer[] initializers, AsyncCallback callback, object state) : base(callback, state) { _channel = channel; _initializers = initializers; _proxy = ServiceChannelFactory.GetServiceChannel(channel.Proxy); this.CallBegin(true); }
private void InitializeServiceChannel(ServiceChannel channel) { ClientRuntime clientRuntime = channel.ClientRuntime; if (clientRuntime != null) { Type contractType = clientRuntime.ContractClientType; Type callbackType = clientRuntime.CallbackClientType; if (contractType != null) { channel.Proxy = ServiceChannelFactory.CreateProxy(contractType, callbackType, MessageDirection.Output, channel); } } if (_listener != null) { _listener.ChannelDispatcher.InitializeChannel((IClientChannel)channel.Proxy); } ((IChannel)channel).Open(); }
bool HandleErrorContinuation(Exception e, RequestContext request, ServiceChannel channel, ref ErrorHandlerFaultInfo faultInfo, bool replied) { if (replied) { try { request.Close(); } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } this.HandleError(e1); } } else { request.Abort(); } if (!this.HandleError(e, ref faultInfo) && this.hasSession) { if (channel != null) { if (replied) { TimeoutHelper timeoutHelper = new TimeoutHelper(CloseAfterFaultTimeout); try { channel.Close(timeoutHelper.RemainingTime()); } catch (Exception e2) { if (Fx.IsFatal(e2)) { throw; } this.HandleError(e2); } try { this.binder.CloseAfterFault(timeoutHelper.RemainingTime()); } catch (Exception e3) { if (Fx.IsFatal(e3)) { throw; } this.HandleError(e3); } } else { channel.Abort(); this.binder.Abort(); } } else { if (replied) { try { this.binder.CloseAfterFault(CloseAfterFaultTimeout); } catch (Exception e4) { if (Fx.IsFatal(e4)) { throw; } this.HandleError(e4); } } else { this.binder.Abort(); } } } return true; }
public bool ChannelHandlerOwnsInstanceContextThrottle; // if true, we are responsible for instance/dynamic throttle public RequestInfo(ChannelHandler channelHandler) { this.Endpoint = null; this.ExistingInstanceContext = null; this.Channel = null; this.EndpointLookupDone = false; this.DispatchRuntime = null; this.RequestContext = null; this.ChannelHandler = channelHandler; this.ChannelHandlerOwnsCallThrottle = false; this.ChannelHandlerOwnsInstanceContextThrottle = false; }
void InputSessionFaultedCore(ServiceChannel channel) { IDuplexContextChannel proxy = channel.Proxy as IDuplexContextChannel; if (proxy != null) { IInputSessionShutdown[] handlers = this.inputSessionShutdownHandlers; try { for (int i = 0; i < handlers.Length; i++) { handlers[i].ChannelFaulted(proxy); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (!this.error.HandleError(e)) { proxy.Abort(); } } } }
bool HandleError(Exception e, RequestContext request, ServiceChannel channel) { ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction); bool replied, replySentAsync; ProvideFaultAndReplyFailure(request, e, ref faultInfo, out replied, out replySentAsync); if (!replySentAsync) { return this.HandleErrorContinuation(e, request, channel, ref faultInfo, replied); } else { return false; } }
void InitializeServiceChannel(ServiceChannel channel) { if (this.wasChannelThrottled) { // TFS#500703, when the idle timeout was hit, the constructor of ServiceChannel will abort itself directly. So // the session throttle will not be released and thus lead to a service unavailablity. // Note that if the channel is already aborted, the next line "channel.ServiceThrottle = this.throttle;" will throw an exception, // so we are not going to do any more work inside this method. // Ideally we should do a thorough refactoring work for this throttling issue. However, it's too risky as a QFE. We should consider // this in a whole release. // Note that the "wasChannelThrottled" boolean will only be true if we aquired the session throttle. So we don't have to check HasSession // again here. if (channel.Aborted && this.throttle != null) { // This line will release the "session" throttle. this.throttle.DeactivateChannel(); } channel.ServiceThrottle = this.throttle; } if (this.InstanceContextServiceThrottle != null) { channel.InstanceContextServiceThrottle = this.InstanceContextServiceThrottle; } ClientRuntime clientRuntime = channel.ClientRuntime; if (clientRuntime != null) { Type contractType = clientRuntime.ContractClientType; Type callbackType = clientRuntime.CallbackClientType; if (contractType != null) { channel.Proxy = ServiceChannelFactory.CreateProxy(contractType, callbackType, MessageDirection.Output, channel); } } if (this.listener != null) { this.listener.ChannelDispatcher.InitializeChannel((IClientChannel)channel.Proxy); } ((IChannel)channel).Open(); }
ServiceChannel GetSessionChannel(Message message, out EndpointDispatcher endpoint, out bool addressMatched) { addressMatched = false; if (this.channel == null) { lock (this.ThisLock) { if (this.channel == null) { endpoint = this.GetEndpointDispatcher(message, out addressMatched); if (endpoint != null) { this.channel = new ServiceChannel(this.binder, endpoint, this.listener.ChannelDispatcher, this.idleManager); this.InitializeServiceChannel(this.channel); } } } } if (this.channel == null) { endpoint = null; } else { endpoint = this.channel.EndpointDispatcher; } return this.channel; }
public void Cleanup() { if (this.ChannelHandlerOwnsInstanceContextThrottle) { this.ChannelHandler.throttle.DeactivateInstanceContext(); this.ChannelHandlerOwnsInstanceContextThrottle = false; } this.Endpoint = null; this.ExistingInstanceContext = null; this.Channel = null; this.EndpointLookupDone = false; this.RequestContext = null; if (this.ChannelHandlerOwnsCallThrottle) { this.ChannelHandler.DispatchDone(); this.ChannelHandlerOwnsCallThrottle = false; } }
private void InitializeServiceChannel(ServiceChannel channel) { if (this.wasChannelThrottled) { channel.ServiceThrottle = this.throttle; } if (this.InstanceContextServiceThrottle != null) { channel.InstanceContextServiceThrottle = this.InstanceContextServiceThrottle; } ClientRuntime clientRuntime = channel.ClientRuntime; if (clientRuntime != null) { System.Type contractClientType = clientRuntime.ContractClientType; System.Type callbackClientType = clientRuntime.CallbackClientType; if (contractClientType != null) { channel.Proxy = ServiceChannelFactory.CreateProxy(contractClientType, callbackClientType, MessageDirection.Output, channel); } } if (this.listener != null) { this.listener.ChannelDispatcher.InitializeChannel((IClientChannel) channel.Proxy); } channel.Open(); }
private bool HandleError(Exception e, RequestContext request, ServiceChannel channel) { bool flag; ErrorHandlerFaultInfo faultInfo = new ErrorHandlerFaultInfo(this.messageVersion.Addressing.DefaultFaultAction); this.ProvideFaultAndReplyFailure(request, e, ref faultInfo, out flag); if (flag) { try { request.Close(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.HandleError(exception); } } else { request.Abort(); } if (!this.HandleError(e, ref faultInfo) && this.hasSession) { if (channel != null) { if (flag) { TimeoutHelper helper = new TimeoutHelper(CloseAfterFaultTimeout); try { channel.Close(helper.RemainingTime()); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } this.HandleError(exception2); } try { this.binder.CloseAfterFault(helper.RemainingTime()); goto Label_0117; } catch (Exception exception3) { if (Fx.IsFatal(exception3)) { throw; } this.HandleError(exception3); goto Label_0117; } } channel.Abort(); this.binder.Abort(); } else { if (flag) { try { this.binder.CloseAfterFault(CloseAfterFaultTimeout); goto Label_0117; } catch (Exception exception4) { if (Fx.IsFatal(exception4)) { throw; } this.HandleError(exception4); goto Label_0117; } } this.binder.Abort(); } } Label_0117: return true; }
internal void InputSessionDoneReceiving(ServiceChannel channel) { if (this.inputSessionShutdownHandlers.Length > 0) { this.InputSessionDoneReceivingCore(channel); } }
internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation, ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread, OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity) { Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null"); Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null"); this.Activity = null; this.EventTraceActivity = eventTraceActivity; this.AsyncResult = null; this.CanSendReply = true; this.Channel = channel; this.channelHandler = channelHandler; this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount); this.CorrelationCallback = null; this.DidDeserializeRequestBody = false; this.TransactionMessageProperty = null; this.TransactedBatchContext = null; this.Error = null; this.ErrorProcessor = null; this.FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction); this.HasSecurityContext = false; this.Host = host; this.Instance = null; this.MessageRpcOwnsInstanceContextThrottle = false; this.NextProcessor = null; this.NotUnderstoodHeaders = null; this.Operation = operation; this.OperationContext = operationContext; this.paused = false; this.ParametersDisposed = false; this.ReceiveContext = null; this.Request = request; this.RequestContext = requestContext; this.RequestContextThrewOnReply = false; this.SuccessfullySendReply = false; this.RequestVersion = request.Version; this.Reply = null; this.ReplyTimeoutHelper = new TimeoutHelper(); this.SecurityContext = null; this.InstanceContext = instanceContext; this.SuccessfullyBoundInstance = false; this.SuccessfullyIncrementedActivity = false; this.SuccessfullyLockedInstance = false; this.switchedThreads = !cleanThread; this.transaction = null; this.InputParameters = null; this.OutputParameters = null; this.ReturnParameter = null; this.isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(this.Channel.DispatchRuntime.InstanceContextProvider); this.invokeContinueGate = null; if (!operation.IsOneWay && !operation.Parent.ManualAddressing) { this.RequestID = request.Headers.MessageId; this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request); } else { this.RequestID = null; this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(); } this.HostingProperty = AspNetEnvironment.Current.GetHostingProperty(request, true); if (DiagnosticUtility.ShouldUseActivity) { this.Activity = TraceUtility.ExtractActivity(this.Request); } if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity) { this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request); } else { this.ResponseActivityId = Guid.Empty; } this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler); if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled) { if (this.Request != null) { this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true); } } }
internal IAsyncResult BeginDisplayInitializationUI(ServiceChannel channel, AsyncCallback callback, object state) { return new DisplayInitializationUIAsyncResult(channel, this.interactiveChannelInitializers, callback, state); }
internal void InputSessionFaulted(ServiceChannel channel) { if (this.inputSessionShutdownHandlers.Length > 0) { this.InputSessionFaultedCore(channel); } }
internal void DisplayInitializationUI(ServiceChannel channel) { this.EndDisplayInitializationUI(this.BeginDisplayInitializationUI(channel, null, null)); }
void AddMessageProperties(Message message, OperationContext context, ServiceChannel replyChannel) { if (context.InternalServiceChannel == replyChannel) { if (context.HasOutgoingMessageHeaders) { message.Headers.CopyHeadersFrom(context.OutgoingMessageHeaders); } if (context.HasOutgoingMessageProperties) { message.Properties.MergeProperties(context.OutgoingMessageProperties); } } }
private void InputSessionDoneReceivingCore(ServiceChannel channel) { IDuplexContextChannel proxy = channel.Proxy as IDuplexContextChannel; if (proxy != null) { IInputSessionShutdown[] inputSessionShutdownHandlers = this.inputSessionShutdownHandlers; try { for (int i = 0; i < inputSessionShutdownHandlers.Length; i++) { inputSessionShutdownHandlers[i].DoneReceiving(proxy); } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (!this.error.HandleError(exception)) { proxy.Abort(); } } } }