Esempio n. 1
0
        public static IRoutingClient Create(RoutingEndpointTrait endpointTrait, RoutingService service, bool impersonating)
        {
            Type           contractType = endpointTrait.RouterContract;
            IRoutingClient client;

            if (contractType == typeof(ISimplexDatagramRouter))
            {
                client = new SimplexDatagramClient(endpointTrait, service.RoutingConfig, impersonating);
            }
            else if (contractType == typeof(IRequestReplyRouter))
            {
                client = new RequestReplyClient(endpointTrait, service.RoutingConfig, impersonating);
            }
            else if (contractType == typeof(ISimplexSessionRouter))
            {
                client = new SimplexSessionClient(endpointTrait, service.RoutingConfig, impersonating);
            }
            else //if (contractType == typeof(IDuplexSessionRouter))
            {
                Fx.Assert(contractType == typeof(IDuplexSessionRouter), "Only one contract type remaining.");
                client = new DuplexSessionClient(service, endpointTrait, impersonating);
            }

            return(client);
        }
Esempio n. 2
0
 internal IRoutingClient GetOrCreateClient <TContract>(RoutingEndpointTrait endpointTrait, bool impersonating)
 {
     if (impersonating && !this.ChannelExtension.HasSession)
     {
         if (this.perMessageChannels == null)
         {
             this.perMessageChannels = new SessionChannels(this.ChannelExtension.ActivityID);
         }
         return(this.perMessageChannels.GetOrCreateClient <TContract>(endpointTrait, this, impersonating));
     }
     else
     {
         return(this.ChannelExtension.SessionChannels.GetOrCreateClient <TContract>(endpointTrait, this, impersonating));
     }
 }
Esempio n. 3
0
        internal IRoutingClient GetOrCreateClient <TContract>(RoutingEndpointTrait key, RoutingService service, bool impersonating)
        {
            IRoutingClient value;

            lock (this.sessions)
            {
                if (!this.sessions.TryGetValue(key, out value))
                {
                    //Create the client here
                    value              = ClientFactory.Create(key, service, impersonating);
                    value.Faulted     += ChannelFaulted;
                    this.sessions[key] = value;
                    sessionList.Add(value);
                }
            }
            return(value);
        }
Esempio n. 4
0
        public void AbortChannel(RoutingEndpointTrait key)
        {
            IRoutingClient client;

            lock (this.sessions)
            {
                if (this.sessions.TryGetValue(key, out client))
                {
                    this.sessions.Remove(key);
                    this.sessionList.Remove(client);
                }
            }

            if (client != null)
            {
                RoutingUtilities.Abort((ICommunicationObject)client, client.Key);
            }
        }
        public override bool Equals(object obj)
        {
            RoutingEndpointTrait other = obj as RoutingEndpointTrait;

            if (other == null)
            {
                return(false);
            }
            if (!object.ReferenceEquals(this.Endpoint, other.Endpoint))
            {
                return(false);
            }
            if (this.RouterContract != other.RouterContract)
            {
                return(false);
            }
            if (!object.ReferenceEquals(this.CallbackInstance, other.CallbackInstance))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
            void Initialize(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, bool impersonating)
            {
                this.thisLock = new object();
                this.Key      = endpointTrait;
                if (TD.RoutingServiceCreatingClientForEndpointIsEnabled())
                {
                    TD.RoutingServiceCreatingClientForEndpoint(this.Key.ToString());
                }
                ServiceEndpoint clientEndpoint = endpointTrait.Endpoint;
                ServiceEndpoint endpoint       = this.Endpoint;
                KeyedByTypeCollection <IEndpointBehavior> behaviors = endpoint.Behaviors;

                endpoint.ListenUri     = clientEndpoint.ListenUri;
                endpoint.ListenUriMode = clientEndpoint.ListenUriMode;
                endpoint.Name          = clientEndpoint.Name;
                foreach (IEndpointBehavior behavior in clientEndpoint.Behaviors)
                {
                    // Remove if present, ok to call if not there (will simply return false)
                    behaviors.Remove(behavior.GetType());
                    behaviors.Add(behavior);
                }

                // If the configuration doesn't explicitly add MustUnderstandBehavior (to override us)
                // add it here, with mustunderstand = false.
                if (behaviors.Find <MustUnderstandBehavior>() == null)
                {
                    behaviors.Add(new MustUnderstandBehavior(false));
                }

                // If the configuration doesn't explicitly turn off marshaling we add it here.
                if (routingConfig.SoapProcessingEnabled && behaviors.Find <SoapProcessingBehavior>() == null)
                {
                    behaviors.Add(new SoapProcessingBehavior());
                }

                ConfigureTransactionFlow(endpoint);
                ConfigureImpersonation(endpoint, impersonating);
            }
Esempio n. 7
0
 protected RoutingClientBase(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, object callbackInstance, bool impersonating)
     : base(new InstanceContext(callbackInstance), endpointTrait.Endpoint.Binding, endpointTrait.Endpoint.Address)
 {
     Initialize(endpointTrait, routingConfig, impersonating);
 }
Esempio n. 8
0
 protected RoutingClientBase(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, bool impersonating)
     : base(endpointTrait.Endpoint.Binding, endpointTrait.Endpoint.Address)
 {
     Initialize(endpointTrait, routingConfig, impersonating);
 }
Esempio n. 9
0
 public RequestReplyClient(RoutingEndpointTrait endpointTrait, RoutingConfiguration routingConfig, bool impersonating)
     : base(endpointTrait, routingConfig, impersonating)
 {
 }
Esempio n. 10
0
 public DuplexSessionClient(RoutingService service, RoutingEndpointTrait endpointTrait, bool impersonating)
     : base(endpointTrait, service.RoutingConfig, new DuplexCallbackProxy(service.ChannelExtension.ActivityID, endpointTrait.CallbackInstance), impersonating)
 {
 }
Esempio n. 11
0
 public SimplexSessionClient(RoutingEndpointTrait endointTrait, RoutingConfiguration routingConfig, bool impersonating)
     : base(endointTrait, routingConfig, impersonating)
 {
 }
Esempio n. 12
0
        bool SendToCurrentClient()
        {
            MessageRpc    messageRpc    = this.service.SessionMessages[this.sessionMessageIndex];
            SendOperation sendOperation = messageRpc.Operations[this.destinationIndex];

            if (sendOperation.Sent)
            {
                this.MoveToNextClientOperation(messageRpc.Operations.Count);
                return(true);
            }
            else if (!this.channelExtension.ReceiveContextEnabled &&
                     this.channelExtension.TransactedReceiveEnabled &&
                     sendOperation.HasAlternate)
            {
                // We can't do error handling for oneway Transactional unless there's RC.
                throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR.ErrorHandlingNotSupportedTxNoRC(messageRpc.OperationContext.Channel.LocalAddress)));
            }

            RoutingEndpointTrait endpointTrait = sendOperation.CurrentEndpoint;

            this.client = this.service.GetOrCreateClient <TContract>(endpointTrait, messageRpc.Impersonating);
            try
            {
                // We always work on cloned message when there are backup endpoints to handle exception cases
                Message message;
                if (messageRpc.Operations.Count == 1 && sendOperation.AlternateEndpointCount == 0)
                {
                    message = messageRpc.Message;
                }
                else
                {
                    message = messageRpc.CreateBuffer().CreateMessage();
                }

                sendOperation.PrepareMessage(message);
                IAsyncResult result;

                if (TD.RoutingServiceTransmittingMessageIsEnabled())
                {
                    TD.RoutingServiceTransmittingMessage(messageRpc.EventTraceActivity, messageRpc.UniqueID, this.destinationIndex.ToString(TD.Culture), this.client.Key.ToString());
                }

                Transaction transaction = this.service.GetTransactionForSending(messageRpc);
                using (this.PrepareTransactionalCall(transaction))
                {
                    IDisposable impersonationContext = null;
                    try
                    {
                        //Perform the assignment in a finally block so it won't be interrupted asynchronously
                        try { }
                        finally
                        {
                            impersonationContext = messageRpc.PrepareCall();
                        }

                        result = this.client.BeginOperation(message, transaction, this.PrepareAsyncCompletion(clientOperationCallback), this);
                    }
                    finally
                    {
                        if (impersonationContext != null)
                        {
                            impersonationContext.Dispose();
                        }
                    }
                }

                if (this.CheckSyncContinue(result))
                {
                    this.ClientOperationComplete(result);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                //See if we can handle this Exception...
                if (this.HandleClientOperationFailure(exception))
                {
                    return(true);
                }
                throw;
            }
        }