Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / ServiceChannel.cs / 1 / ServiceChannel.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.ServiceModel; using System.ServiceModel.Dispatcher; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.ServiceModel.Diagnostics; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.ServiceModel.Security.Tokens; using System.Net.Security; using System.ServiceModel.Security; using System.Threading; using System.Globalization; using System.Xml; using System.Security; // This class is sealed because the constructor could call Abort, which is virtual internal sealed class ServiceChannel : CommunicationObject, IChannel, IClientChannel, IDuplexContextChannel, IOutputChannel, IRequestChannel,IServiceChannel { int activityCount = 0; bool allowInitializationUI = true; bool allowOutputBatching = false; bool autoClose = true; CallOnceManager autoDisplayUIManager; CallOnceManager autoOpenManager; readonly IChannelBinder binder; readonly ChannelDispatcher channelDispatcher; ClientRuntime clientRuntime; readonly bool closeBinder = true; bool closeFactory; bool didInteractiveInitialization; bool doneReceiving; EndpointDispatcher endpointDispatcher; bool explicitlyOpened; ExtensionCollectionextensions; readonly ServiceChannelFactory factory; readonly bool hasSession; readonly SessionIdleManager idleManager; InstanceContext instanceContext; ServiceThrottle instanceContextServiceThrottle; bool isPending; readonly bool isReplyChannel; EndpointAddress localAddress; readonly MessageVersion messageVersion; readonly bool openBinder = false; TimeSpan operationTimeout; object proxy; ServiceThrottle serviceThrottle; string terminatingOperationName; InstanceContext wmiInstanceContext; bool wasChannelAutoClosed; EventHandler unknownMessageReceived; ServiceChannel(IChannelBinder binder, MessageVersion messageVersion, IDefaultCommunicationTimeouts timeouts) { if (binder == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binder"); } this.messageVersion = messageVersion; this.binder = binder; this.isReplyChannel = this.binder.Channel is IReplyChannel; IChannel innerChannel = binder.Channel; this.hasSession = (innerChannel is ISessionChannel ) || (innerChannel is ISessionChannel ) || (innerChannel is ISessionChannel ); this.binder.Channel.Faulted += OnInnerChannelFaulted; this.IncrementActivity(); this.openBinder = (binder.Channel.State == CommunicationState.Created); this.operationTimeout = timeouts.SendTimeout; } internal ServiceChannel(ServiceChannelFactory factory, IChannelBinder binder) : this(binder, factory.MessageVersion, factory) { this.factory = factory; this.clientRuntime = factory.ClientRuntime; DispatchRuntime dispatch = factory.ClientRuntime.DispatchRuntime; if (dispatch != null) { this.autoClose = dispatch.AutomaticInputSessionShutdown; } factory.ChannelCreated(this); } internal ServiceChannel(IChannelBinder binder, EndpointDispatcher endpointDispatcher, ChannelDispatcher channelDispatcher, SessionIdleManager idleManager) : this(binder, channelDispatcher.MessageVersion, channelDispatcher.DefaultCommunicationTimeouts) { if (endpointDispatcher == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("endpointDispatcher"); } this.channelDispatcher = channelDispatcher; this.endpointDispatcher = endpointDispatcher; this.clientRuntime = endpointDispatcher.DispatchRuntime.CallbackClientRuntime; this.autoClose = endpointDispatcher.DispatchRuntime.AutomaticInputSessionShutdown; this.isPending = true; IDefaultCommunicationTimeouts timeouts = channelDispatcher.DefaultCommunicationTimeouts; this.idleManager = idleManager; if (!binder.HasSession) this.closeBinder = false; if (this.idleManager != null) { bool didIdleAbort; this.idleManager.RegisterChannel(this, out didIdleAbort); if (didIdleAbort) { this.Abort(); } } } CallOnceManager AutoOpenManager { get { if (!this.explicitlyOpened && (this.autoOpenManager == null)) { this.EnsureAutoOpenManagers(); } return this.autoOpenManager; } } CallOnceManager AutoDisplayUIManager { get { if (!this.explicitlyOpened && (this.autoDisplayUIManager == null)) { this.EnsureAutoOpenManagers(); } return this.autoDisplayUIManager; } } internal bool CloseFactory { get { return this.closeFactory; } set { this.closeFactory = value; } } protected override TimeSpan DefaultCloseTimeout { get { return this.CloseTimeout; } } protected override TimeSpan DefaultOpenTimeout { get { return this.OpenTimeout; } } internal DispatchRuntime DispatchRuntime { get { if (this.endpointDispatcher != null) { return this.endpointDispatcher.DispatchRuntime; } if (this.clientRuntime != null) { return this.clientRuntime.DispatchRuntime; } return null; } } internal MessageVersion MessageVersion { get { return this.messageVersion; } } internal IChannelBinder Binder { get { return this.binder; } } internal TimeSpan CloseTimeout { get { if (this.IsClient) { return factory.InternalCloseTimeout; } else { return this.ChannelDispatcher.InternalCloseTimeout; } } } internal ChannelDispatcher ChannelDispatcher { get { return this.channelDispatcher; } } internal EndpointDispatcher EndpointDispatcher { get { return this.endpointDispatcher; } set { lock (this.ThisLock) { this.endpointDispatcher = value; this.clientRuntime = value.DispatchRuntime.CallbackClientRuntime; } } } internal ServiceChannelFactory Factory { get { return this.factory; } } internal IChannel InnerChannel { get { return this.binder.Channel; } } internal bool IsPending { get { return this.isPending; } set { this.isPending = value; } } internal bool HasSession { get { return hasSession; } } internal bool IsClient { get { return this.factory != null; } } internal bool IsReplyChannel { get { return this.isReplyChannel; } } public Uri ListenUri { get { return this.binder.ListenUri; } } public EndpointAddress LocalAddress { get { if (this.localAddress == null) { if (this.endpointDispatcher != null) { this.localAddress = this.endpointDispatcher.EndpointAddress; } else { this.localAddress = this.binder.LocalAddress; } } return this.localAddress; } } internal TimeSpan OpenTimeout { get { if (this.IsClient) { return factory.InternalOpenTimeout; } else { return this.ChannelDispatcher.InternalOpenTimeout; } } } public TimeSpan OperationTimeout { get { return this.operationTimeout; } set { if (value < TimeSpan.Zero) { string message = SR.GetString(SR.SFxTimeoutOutOfRange0); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, message)); } if (TimeoutHelper.IsTooLarge(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", value, SR.GetString(SR.SFxTimeoutOutOfRangeTooBig))); } this.operationTimeout = value; } } internal object Proxy { get { object proxy = this.proxy; if (proxy != null) return proxy; else return this; } set { this.proxy = value; base.EventSender = value; // need to use "proxy" as open/close event source } } internal ClientRuntime ClientRuntime { get { return this.clientRuntime; } } public EndpointAddress RemoteAddress { get { IOutputChannel outputChannel = this.InnerChannel as IOutputChannel; if (outputChannel != null) return outputChannel.RemoteAddress; IRequestChannel requestChannel = this.InnerChannel as IRequestChannel; if (requestChannel != null) return requestChannel.RemoteAddress; return null; } } ProxyOperationRuntime UnhandledProxyOperation { get { return this.ClientRuntime.GetRuntime().UnhandledProxyOperation; } } public Uri Via { get { IOutputChannel outputChannel = this.InnerChannel as IOutputChannel; if (outputChannel != null) return outputChannel.Via; IRequestChannel requestChannel = this.InnerChannel as IRequestChannel; if (requestChannel != null) return requestChannel.Via; return null; } } internal InstanceContext InstanceContext { get { return this.instanceContext; } set { this.instanceContext = value; } } internal ServiceThrottle InstanceContextServiceThrottle { get { return this.instanceContextServiceThrottle; } set { this.instanceContextServiceThrottle = value; } } internal ServiceThrottle ServiceThrottle { get { return this.serviceThrottle; } set { this.ThrowIfDisposed(); this.serviceThrottle = value; } } internal InstanceContext WmiInstanceContext { get { return this.wmiInstanceContext; } set { this.wmiInstanceContext = value; } } void BindDuplexCallbacks() { IDuplexChannel duplexChannel = this.InnerChannel as IDuplexChannel; if ((duplexChannel != null) && (this.factory != null) && (this.instanceContext != null)) { if (this.binder is DuplexChannelBinder) ((DuplexChannelBinder)this.binder).EnsurePumping(); } } internal bool CanCastTo(Type t) { if (t.IsAssignableFrom(typeof(IClientChannel))) return true; if (t.IsAssignableFrom(typeof(IDuplexContextChannel))) return this.InnerChannel is IDuplexChannel; if (t.IsAssignableFrom(typeof(IServiceChannel))) return true; return false; } internal void CompletedIOOperation() { if (this.idleManager != null) { this.idleManager.CompletedActivity(); } } void EnsureAutoOpenManagers() { lock (this.ThisLock) { if (!this.explicitlyOpened) { if (this.autoOpenManager == null) { this.autoOpenManager = new CallOnceManager(this, CallOpenOnce.Instance); } if (this.autoDisplayUIManager == null) { this.autoDisplayUIManager = new CallOnceManager(this, CallDisplayUIOnce.Instance); } } } } void EnsureDisplayUI() { CallOnceManager manager = this.AutoDisplayUIManager; if (manager != null) { manager.CallOnce(TimeSpan.MaxValue, null); } this.ThrowIfInitializationUINotCalled(); } IAsyncResult BeginEnsureDisplayUI(AsyncCallback callback, object state) { CallOnceManager manager = this.AutoDisplayUIManager; if (manager != null) { return manager.BeginCallOnce(TimeSpan.MaxValue, null, callback, state); } else { return new CallOnceCompletedAsyncResult(callback, state); } } void EndEnsureDisplayUI(IAsyncResult result) { CallOnceManager manager = this.AutoDisplayUIManager; if (manager != null) { manager.EndCallOnce(result); } else { CallOnceCompletedAsyncResult.End(result); } this.ThrowIfInitializationUINotCalled(); } void EnsureOpened(TimeSpan timeout) { CallOnceManager manager = this.AutoOpenManager; if (manager != null) { manager.CallOnce(timeout, this.autoDisplayUIManager); } this.ThrowIfOpening(); this.ThrowIfDisposedOrNotOpen(); } IAsyncResult BeginEnsureOpened(TimeSpan timeout, AsyncCallback callback, object state) { CallOnceManager manager = this.AutoOpenManager; if (manager != null) { return manager.BeginCallOnce(timeout, this.autoDisplayUIManager, callback, state); } else { this.ThrowIfOpening(); this.ThrowIfDisposedOrNotOpen(); return new CallOnceCompletedAsyncResult(callback, state); } } void EndEnsureOpened(IAsyncResult result) { CallOnceManager manager = this.AutoOpenManager; if (manager != null) { manager.EndCallOnce(result); } else { CallOnceCompletedAsyncResult.End(result); } } public T GetProperty () where T : class { IChannel innerChannel = this.InnerChannel; if (innerChannel != null) return innerChannel.GetProperty (); return null; } void PrepareCall(ProxyOperationRuntime operation, bool oneway, ref ProxyRpc rpc) { OperationContext context = OperationContext.Current; // Doing a request reply callback when dispatching in-order deadlocks. // We never receive the reply until we finish processing the current message. if (!oneway) { DispatchRuntime dispatchBehavior = this.ClientRuntime.DispatchRuntime; if ((dispatchBehavior != null) && (dispatchBehavior.ConcurrencyMode == ConcurrencyMode.Single)) { if ((context != null) && (!context.IsUserContext) && (context.InternalServiceChannel == this)) { if (dispatchBehavior.IsOnServer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxCallbackRequestReplyInOrder1,typeof(ServiceBehaviorAttribute).Name))); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxCallbackRequestReplyInOrder1, typeof(CallbackBehaviorAttribute).Name))); } } } } if ((this.State == CommunicationState.Created) && !operation.IsInitiating) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNonInitiatingOperation1, operation.Name))); } if (this.terminatingOperationName != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxTerminatingOperationAlreadyCalled1, this.terminatingOperationName))); } if (this.wasChannelAutoClosed) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(SR.GetString(SR.SFxClientOutputSessionAutoClosed))); } operation.BeforeRequest(ref rpc); AddMessageProperties(rpc.Request, context); if (!oneway && !this.ClientRuntime.ManualAddressing && rpc.Request.Version.Addressing != AddressingVersion.None) { RequestReplyCorrelator.PrepareRequest(rpc.Request); MessageHeaders headers = rpc.Request.Headers; EndpointAddress localAddress = this.LocalAddress; EndpointAddress replyTo = headers.ReplyTo; if (replyTo == null) { headers.ReplyTo = localAddress ?? EndpointAddress.AnonymousAddress; } if (this.IsClient && (localAddress != null) && !localAddress.IsAnonymous) { Uri localUri = localAddress.Uri; if ((replyTo != null) && !replyTo.IsAnonymous && (localUri != replyTo.Uri)) { string text = SR.GetString(SR.SFxRequestHasInvalidReplyToOnClient, replyTo.Uri, localUri); Exception error = new InvalidOperationException(text); throw TraceUtility.ThrowHelperError(error, rpc.Request); } EndpointAddress faultTo = headers.FaultTo; if ((faultTo != null) && !faultTo.IsAnonymous && (localUri != faultTo.Uri)) { string text = SR.GetString(SR.SFxRequestHasInvalidFaultToOnClient, faultTo.Uri, localUri); Exception error = new InvalidOperationException(text); throw TraceUtility.ThrowHelperError(error, rpc.Request); } if (this.messageVersion.Addressing == AddressingVersion.WSAddressingAugust2004) { EndpointAddress from = headers.From; if ((from != null) && !from.IsAnonymous && (localUri != from.Uri)) { string text = SR.GetString(SR.SFxRequestHasInvalidFromOnClient, from.Uri, localUri); Exception error = new InvalidOperationException(text); throw TraceUtility.ThrowHelperError(error, rpc.Request); } } } } if (rpc.Activity != null) { TraceUtility.SetActivity(rpc.Request, rpc.Activity); if (TraceUtility.ShouldPropagateActivity) { TraceUtility.AddActivityHeader(rpc.Request); } } else if (TraceUtility.PropagateUserActivity) { TraceUtility.AddAmbientActivityToMessage(rpc.Request); } operation.Parent.BeforeSendRequest(ref rpc); if (MessageLogger.LogMessagesAtServiceLevel) { MessageLogger.LogMessage(ref rpc.Request, (oneway ? MessageLoggingSource.ServiceLevelSendDatagram : MessageLoggingSource.ServiceLevelSendRequest) | MessageLoggingSource.LastChance); } } internal IAsyncResult BeginCall(string action, bool oneway, ProxyOperationRuntime operation, object[] ins, AsyncCallback callback, object asyncState) { return this.BeginCall(action, oneway, operation, ins, this.operationTimeout, callback, asyncState); } internal IAsyncResult BeginCall(string action, bool oneway, ProxyOperationRuntime operation, object[] ins, TimeSpan timeout, AsyncCallback callback, object asyncState) { this.ThrowIfDisallowedInitializationUI(); this.ThrowIfIdleAborted(operation); ServiceModelActivity serviceModelActivity = null; if (DiagnosticUtility.ShouldUseActivity) { serviceModelActivity = ServiceModelActivity.CreateActivity(true); callback = TraceUtility.WrapExecuteUserCodeAsyncCallback(callback); } SendAsyncResult result; using (Activity boundOperation = ServiceModelActivity.BoundOperation(serviceModelActivity, true)) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(serviceModelActivity, SR.GetString(SR.ActivityProcessAction, action), ActivityType.ProcessAction); } result = new SendAsyncResult(this, operation, action, ins, oneway, timeout, callback, asyncState); if (DiagnosticUtility.ShouldUseActivity) { result.Rpc.Activity = serviceModelActivity; } result.Begin(); } return result; } internal object Call(string action, bool oneway, ProxyOperationRuntime operation, object[] ins, object[] outs) { return this.Call(action, oneway, operation, ins, outs, this.operationTimeout); } internal object Call(string action, bool oneway, ProxyOperationRuntime operation, object[] ins, object[] outs, TimeSpan timeout) { this.ThrowIfDisallowedInitializationUI(); this.ThrowIfIdleAborted(operation); ProxyRpc rpc = new ProxyRpc(this, operation, action, ins, timeout); using (rpc.Activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivity() : null) { if (DiagnosticUtility.ShouldUseActivity) { ServiceModelActivity.Start(rpc.Activity, SR.GetString(SR.ActivityProcessAction, action), ActivityType.ProcessAction); } this.PrepareCall(operation, oneway, ref rpc); if (!this.explicitlyOpened) { this.EnsureDisplayUI(); this.EnsureOpened(rpc.TimeoutHelper.RemainingTime()); } else { this.ThrowIfOpening(); this.ThrowIfDisposedOrNotOpen(); } try { ConcurrencyBehavior.UnlockInstanceBeforeCallout(OperationContext.Current); if (oneway) { this.binder.Send(rpc.Request, rpc.TimeoutHelper.RemainingTime()); } else { rpc.Reply = this.binder.Request(rpc.Request, rpc.TimeoutHelper.RemainingTime()); if (rpc.Reply == null) { this.ThrowIfFaulted(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.SFxServerDidNotReply))); } } } finally { this.CompletedIOOperation(); CallOnceManager.SignalNextIfNonNull(this.autoOpenManager); ConcurrencyBehavior.LockInstanceAfterCallout(OperationContext.Current); } rpc.OutputParameters = outs; this.HandleReply(operation, ref rpc); } return rpc.ReturnValue; } internal object EndCall(string action, object[] outs, IAsyncResult result) { SendAsyncResult sendResult = result as SendAsyncResult; if (sendResult == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SFxInvalidCallbackIAsyncResult))); using (ServiceModelActivity rpcActivity = sendResult.Rpc.Activity) { using (ServiceModelActivity.BoundOperation(rpcActivity, true)) { if (sendResult.Rpc.Activity != null && DiagnosticUtility.ShouldUseActivity) { sendResult.Rpc.Activity.Resume(); } if (sendResult.Rpc.Channel != this) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("result", SR.GetString(SR.AsyncEndCalledOnWrongChannel)); if (action != MessageHeaders.WildcardAction && action != sendResult.Rpc.Action) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("result", SR.GetString(SR.AsyncEndCalledWithAnIAsyncResult)); SendAsyncResult.End(sendResult); sendResult.Rpc.OutputParameters = outs; this.HandleReply(sendResult.Rpc.Operation, ref sendResult.Rpc); if (sendResult.Rpc.Activity != null) { sendResult.Rpc.Activity = null; } return sendResult.Rpc.ReturnValue; } } } internal void DecrementActivity() { int updatedActivityCount = Interlocked.Decrement(ref this.activityCount); if (!((updatedActivityCount >= 0))) { DiagnosticUtility.DebugAssert("ServiceChannel.DecrementActivity: (updatedActivityCount >= 0)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(true); } if (updatedActivityCount == 0 && this.autoClose) { try { if (this.State == CommunicationState.Opened) { if (this.IsClient) { ISessionChannel duplexSessionChannel = this.InnerChannel as ISessionChannel ; if (duplexSessionChannel != null) { duplexSessionChannel.Session.CloseOutputSession(this.CloseTimeout); this.wasChannelAutoClosed = true; } } else { this.Close(this.CloseTimeout); } } } catch (CommunicationException e) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Information); } } catch (TimeoutException e) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Information); } } catch (ObjectDisposedException e) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Information); } } catch (InvalidOperationException e) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(e, TraceEventType.Information); } } } } internal void FireUnknownMessageReceived(Message message) { EventHandler handler = this.unknownMessageReceived; if (handler != null) handler(this.proxy, new UnknownMessageReceivedEventArgs(message)); } TimeoutException GetOpenTimeoutException(TimeSpan timeout) { EndpointAddress address = this.RemoteAddress ?? this.LocalAddress; if (address != null) { return new TimeoutException(SR.GetString(SR.TimeoutServiceChannelConcurrentOpen2, address, timeout)); } else { return new TimeoutException(SR.GetString(SR.TimeoutServiceChannelConcurrentOpen1, timeout)); } } internal void HandleReceiveComplete(RequestContext context) { if (context == null && HasSession) { bool first; lock (this.ThisLock) { first = !this.doneReceiving; this.doneReceiving = true; } if (first) { DispatchRuntime dispatchBehavior = this.ClientRuntime.DispatchRuntime; if (dispatchBehavior != null) dispatchBehavior.GetRuntime().InputSessionDoneReceiving(this); this.DecrementActivity(); } } } void HandleReply(ProxyOperationRuntime operation, ref ProxyRpc rpc) { try { if (rpc.Reply != null) { if (MessageLogger.LogMessagesAtServiceLevel) { MessageLogger.LogMessage(ref rpc.Reply, MessageLoggingSource.ServiceLevelReceiveReply | MessageLoggingSource.LastChance); } operation.Parent.AfterReceiveReply(ref rpc); if ((operation.ReplyAction != MessageHeaders.WildcardAction) && !rpc.Reply.IsFault && rpc.Reply.Headers.Action != null) { if (String.CompareOrdinal(operation.ReplyAction, rpc.Reply.Headers.Action) != 0) { Exception error = new ProtocolException(SR.GetString(SR.SFxReplyActionMismatch3, operation.Name, rpc.Reply.Headers.Action, operation.ReplyAction)); this.TerminateIfNecessary(ref rpc); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); } } if (operation.DeserializeReply && rpc.Reply.IsFault && messageVersion.Envelope != EnvelopeVersion.None) { MessageFault fault = MessageFault.CreateFault(rpc.Reply, this.clientRuntime.MaxFaultSize); string action = rpc.Reply.Headers.Action; if (action == rpc.Reply.Version.Addressing.DefaultFaultAction) { action = null; } ThrowIfFaultUnderstood(rpc.Reply, fault, action, rpc.Reply.Version, rpc.Channel.GetProperty ()); FaultException fe = rpc.Operation.FaultFormatter.Deserialize(fault, action); this.TerminateIfNecessary(ref rpc); throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(fe); } operation.AfterReply(ref rpc); } } finally { if (operation.SerializeRequest) { rpc.Request.Close(); } OperationContext operationContext = OperationContext.Current; bool consumed = ((rpc.Reply != null) && (rpc.Reply.State != MessageState.Created)); if ((operationContext != null) && operationContext.IsUserContext) { operationContext.SetClientReply(rpc.Reply, consumed); } else if (consumed) { rpc.Reply.Close(); } } this.TerminateIfNecessary(ref rpc); } void TerminateIfNecessary(ref ProxyRpc rpc) { if (rpc.Operation.IsTerminating) { this.terminatingOperationName = rpc.Operation.Name; TerminatingOperationBehavior.AfterReply(ref rpc); } } void ThrowIfFaultUnderstood(Message reply, MessageFault fault, string action, MessageVersion version, FaultConverter faultConverter) { Exception exception; if (faultConverter != null && faultConverter.TryCreateException(reply, fault, out exception)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(exception); } bool checkSender; bool checkReceiver; FaultCode code; if (version.Envelope == EnvelopeVersion.Soap11) { checkSender = true; checkReceiver = true; code = fault.Code; } else { checkSender = fault.Code.IsSenderFault; checkReceiver = fault.Code.IsReceiverFault; code = fault.Code.SubCode; } if (code == null) { return; } if (code.Namespace == null) { return; } if (checkSender) { if (string.Compare(code.Namespace, FaultCodeConstants.Namespaces.NetDispatch, StringComparison.Ordinal) == 0) { if (string.Compare(code.Name, FaultCodeConstants.Codes.SessionTerminated, StringComparison.Ordinal) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new ChannelTerminatedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text)); } if (string.Compare(code.Name, FaultCodeConstants.Codes.TransactionAborted, StringComparison.Ordinal) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new ProtocolException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text)); } } // throw SecurityAccessDeniedException explicitly if (string.Compare(code.Namespace, SecurityVersion.Default.HeaderNamespace.Value, StringComparison.Ordinal) == 0) { if (string.Compare(code.Name, SecurityVersion.Default.FailedAuthenticationFaultCode.Value, StringComparison.Ordinal) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityAccessDeniedException(fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text)); } } } if (checkReceiver) { if (string.Compare(code.Namespace, FaultCodeConstants.Namespaces.NetDispatch, StringComparison.Ordinal) == 0) { if (string.Compare(code.Name, FaultCodeConstants.Codes.InternalServiceFault, StringComparison.Ordinal) == 0) { if (this.HasSession) { this.Fault(); } if (fault.HasDetail) { ExceptionDetail detail = fault.GetDetail (); throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new FaultException (detail, fault.Reason, fault.Code, action)); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new FaultException(fault, action)); } if (string.Compare(code.Name, FaultCodeConstants.Codes.DeserializationFailed, StringComparison.Ordinal) == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new ProtocolException( fault.Reason.GetMatchingTranslation(CultureInfo.CurrentCulture).Text)); } } } } void ThrowIfIdleAborted(ProxyOperationRuntime operation) { if (this.idleManager != null && this.idleManager.DidIdleAbort) { string text = SR.GetString(SR.SFxServiceChannelIdleAborted, operation.Name); Exception error = new CommunicationObjectAbortedException(text); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); } } void ThrowIfInitializationUINotCalled() { if (!this.didInteractiveInitialization && (this.ClientRuntime.InteractiveChannelInitializers.Count > 0)) { IInteractiveChannelInitializer example = this.ClientRuntime.InteractiveChannelInitializers[0]; string text = SR.GetString(SR.SFxInitializationUINotCalled, example.GetType().ToString()); Exception error = new InvalidOperationException(text); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); } } void ThrowIfDisallowedInitializationUI() { if (!this.allowInitializationUI) { this.ThrowIfDisallowedInitializationUICore(); } } void ThrowIfDisallowedInitializationUICore() { if (this.ClientRuntime.InteractiveChannelInitializers.Count > 0) { IInteractiveChannelInitializer example = this.ClientRuntime.InteractiveChannelInitializers[0]; string text = SR.GetString(SR.SFxInitializationUIDisallowed, example.GetType().ToString()); Exception error = new InvalidOperationException(text); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error); } } void ThrowIfOpening() { if (this.State == CommunicationState.Opening) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxCannotCallAutoOpenWhenExplicitOpenCalled))); } } internal void IncrementActivity() { Interlocked.Increment(ref this.activityCount); } void OnInnerChannelFaulted(object sender, EventArgs e) { this.Fault(); if (this.HasSession) { DispatchRuntime dispatchRuntime = this.ClientRuntime.DispatchRuntime; if (dispatchRuntime != null) { dispatchRuntime.GetRuntime().InputSessionFaulted(this); } } if (this.autoClose && !this.IsClient) { this.Abort(); } } void AddMessageProperties(Message message, OperationContext context) { if (this.allowOutputBatching) { message.Properties.AllowOutputBatching = true; } if (context != null && context.InternalServiceChannel == this) { if (!context.OutgoingMessageVersion.IsMatch(message.Headers.MessageVersion)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException( SR.GetString(SR.SFxVersionMismatchInOperationContextAndMessage2, context.OutgoingMessageVersion, message.Headers.MessageVersion) )); } if (context.HasOutgoingMessageHeaders) { message.Headers.CopyHeadersFrom(context.OutgoingMessageHeaders); } if (context.HasOutgoingMessageProperties) { message.Properties.CopyProperties(context.OutgoingMessageProperties); } } } #region IChannel Members public void Send(Message message) { this.Send(message, this.OperationTimeout); } public void Send(Message message, TimeSpan timeout) { ProxyOperationRuntime operation = UnhandledProxyOperation; this.Call(message.Headers.Action, true, operation, new object[] { message }, EmptyArray
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Baml2006ReaderContext.cs
- Compiler.cs
- VisemeEventArgs.cs
- SiteOfOriginContainer.cs
- SingleAnimation.cs
- DrawingAttributes.cs
- FrameworkTextComposition.cs
- ProgressBar.cs
- SourceFilter.cs
- HttpFileCollectionBase.cs
- ProfileModule.cs
- EventData.cs
- CodeTypeConstructor.cs
- ProfileService.cs
- ValidationError.cs
- IntPtr.cs
- TransformFinalBlockRequest.cs
- DataBindingHandlerAttribute.cs
- AlgoModule.cs
- MutableAssemblyCacheEntry.cs
- ObfuscationAttribute.cs
- BehaviorService.cs
- UICuesEvent.cs
- NameTable.cs
- Mappings.cs
- FileDetails.cs
- GreaterThanOrEqual.cs
- CollectionsUtil.cs
- ColorKeyFrameCollection.cs
- WmlLabelAdapter.cs
- PTConverter.cs
- ApplicationTrust.cs
- CompositeClientFormatter.cs
- PropertySet.cs
- SerializationInfo.cs
- TextEditorThreadLocalStore.cs
- WorkflowRuntimeElement.cs
- RepeaterItem.cs
- Byte.cs
- FlowDocumentReader.cs
- ImageInfo.cs
- GuidConverter.cs
- LabelTarget.cs
- MailAddressCollection.cs
- ValueTypeFixupInfo.cs
- DecoderBestFitFallback.cs
- FrameworkTextComposition.cs
- FramingChannels.cs
- AnonymousIdentificationModule.cs
- GlyphTypeface.cs
- PropertyGroupDescription.cs
- BitmapMetadata.cs
- Pens.cs
- User.cs
- LoginUtil.cs
- SqlBuffer.cs
- DecoratedNameAttribute.cs
- SelectionProviderWrapper.cs
- FormsAuthenticationTicket.cs
- BinHexDecoder.cs
- SafeCryptoHandles.cs
- validationstate.cs
- XPathNavigatorKeyComparer.cs
- WsdlHelpGeneratorElement.cs
- ZipArchive.cs
- MessageEncodingBindingElementImporter.cs
- InternalBufferOverflowException.cs
- HtmlAnchor.cs
- ObjectQueryExecutionPlan.cs
- GridViewPageEventArgs.cs
- UnmanagedBitmapWrapper.cs
- StrongName.cs
- ItemType.cs
- UserControlBuildProvider.cs
- TraceSource.cs
- _SSPISessionCache.cs
- WebPartConnectionsEventArgs.cs
- SafeHandles.cs
- UrlUtility.cs
- ImmComposition.cs
- CodeAssignStatement.cs
- TextTreeInsertElementUndoUnit.cs
- WebPartConnection.cs
- EncoderNLS.cs
- DataGridCell.cs
- DataContractSerializerOperationBehavior.cs
- DbConnectionOptions.cs
- Int32AnimationUsingKeyFrames.cs
- QueryContinueDragEvent.cs
- ToolBarButton.cs
- GlobalProxySelection.cs
- InvalidateEvent.cs
- ListCardsInFileRequest.cs
- FormsAuthenticationTicket.cs
- _NetRes.cs
- ConvertEvent.cs
- BStrWrapper.cs
- SearchExpression.cs
- XmlSignatureProperties.cs
- XamlStyleSerializer.cs