private void EnsureOrderedDeliveryRequirements(string name, Binding binding)
 {
     if (this.RequireOrderedDelivery)
     {
         IBindingDeliveryCapabilities property = binding.GetProperty<IBindingDeliveryCapabilities>(new BindingParameterCollection());
         if (property == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SinceTheBindingForDoesnTSupportIBindingCapabilities1_1", new object[] { name })));
         }
         if (!property.AssuresOrderedDelivery)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("TheBindingForDoesnTSupportOrderedDelivery1", new object[] { name })));
         }
     }
 }
        internal static bool IsTransactedReceive(Binding binding, BindingParameterCollection bindingParameters)
        {
            // New school
            ITransactedBindingElement transactedBindingElement = binding.GetProperty<ITransactedBindingElement>(bindingParameters);
            if (transactedBindingElement != null)
            {
                return transactedBindingElement.TransactedReceiveEnabled;
            }

            // Old School
            foreach (BindingElement element in binding.CreateBindingElements())
            {
                transactedBindingElement = element as ITransactedBindingElement;
                if (transactedBindingElement != null && transactedBindingElement.TransactedReceiveEnabled)
                {
                    return true;
                }
            }
            return false;
        }
 private void EnsureQueuedDeliveryRequirements(string name, Binding binding)
 {
     if ((this.QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.Required) || (this.QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.NotAllowed))
     {
         IBindingDeliveryCapabilities property = binding.GetProperty<IBindingDeliveryCapabilities>(new BindingParameterCollection());
         if (property == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SinceTheBindingForDoesnTSupportIBindingCapabilities2_1", new object[] { name })));
         }
         bool queuedDelivery = property.QueuedDelivery;
         if ((this.QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.Required) && !queuedDelivery)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("BindingRequirementsAttributeRequiresQueuedDelivery1", new object[] { name })));
         }
         if ((this.QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.NotAllowed) && queuedDelivery)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("BindingRequirementsAttributeDisallowsQueuedDelivery1", new object[] { name })));
         }
     }
 }
示例#4
0
 private bool IsMulticast(Binding binding)
 {
     IBindingMulticastCapabilities multicast = binding.GetProperty<IBindingMulticastCapabilities>(new BindingParameterCollection());
     return (multicast != null) && multicast.IsMulticast;
 }
        static Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels,
                                                 Binding binding, BindingParameterCollection parameters,
                                                 Uri listenUriBaseAddress, string listenUriRelativeAddress,
                                                 ListenUriMode listenUriMode, ServiceThrottle throttle,
                                                 out IChannelListener result, bool supportContextSession)
        {
            // if actuallyCreate is true, then this behaves like CreateListener()
            // else this behaves like CanCreateListener()
            // result is channel type that was (would be) created, null if can't create
            // 
            // Ugly API helps refactor common code in these two similar-but-different methods

            result = null;

            for (int i = 0; i < supportedChannels.Length; i++)
            {
                Type channelType = supportedChannels[i];

                if (channelType == typeof(IInputChannel))
                {
                    if (binding.CanBuildChannelListener<IInputChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IInputChannel);
                    }
                }
                if (channelType == typeof(IReplyChannel))
                {
                    if (binding.CanBuildChannelListener<IReplyChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IReplyChannel);
                    }
                }
                if (channelType == typeof(IDuplexChannel))
                {
                    if (binding.CanBuildChannelListener<IDuplexChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IDuplexChannel);
                    }
                }
                if (channelType == typeof(IInputSessionChannel))
                {
                    if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IInputSessionChannel);
                    }
                }
                if (channelType == typeof(IReplySessionChannel))
                {
                    if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IReplySessionChannel);
                    }
                }
                if (channelType == typeof(IDuplexSessionChannel))
                {
                    if (binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IDuplexSessionChannel);
                    }
                }
            }

            // If the binding does not support the type natively, try to adapt
            for (int i = 0; i < supportedChannels.Length; i++)
            {
                Type channelType = supportedChannels[i];

                // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well and adapt them
                if (channelType == typeof(IInputChannel))
                {
                    if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            IChannelListener<IInputSessionChannel> temp = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            result = DatagramAdapter.GetInputListener(temp, throttle, binding);
                        }
                        return typeof(IInputSessionChannel);
                    }
                }

                if (channelType == typeof(IReplyChannel))
                {
                    if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            IChannelListener<IReplySessionChannel> temp = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            result = DatagramAdapter.GetReplyListener(temp, throttle, binding);
                        }
                        return typeof(IReplySessionChannel);
                    }
                }

                if (supportContextSession)
                {
                    // and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so 
                    // accept datagram variants if that is the case
                    if (channelType == typeof(IReplySessionChannel))
                    {
                        if (binding.CanBuildChannelListener<IReplyChannel>(parameters)
                            && binding.GetProperty<IContextSessionProvider>(parameters) != null)
                        {
                            if (actuallyCreate)
                            {
                                result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            }
                            return typeof(IReplyChannel);
                        }
                    }
                }
            }

            return null;
        }
 private bool IsMulticast(Binding binding)
 {
     IBindingMulticastCapabilities property = binding.GetProperty<IBindingMulticastCapabilities>(new BindingParameterCollection());
     return ((property != null) && property.IsMulticast);
 }
 private static System.Type MaybeCreateListener(bool actuallyCreate, System.Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, out IChannelListener result, bool supportContextSession)
 {
     result = null;
     for (int i = 0; i < supportedChannels.Length; i++)
     {
         System.Type type = supportedChannels[i];
         if ((type == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IInputChannel);
         }
         if ((type == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplyChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplyChannel);
         }
         if ((type == typeof(IDuplexChannel)) && binding.CanBuildChannelListener<IDuplexChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IDuplexChannel);
         }
         if ((type == typeof(IInputSessionChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IInputSessionChannel);
         }
         if ((type == typeof(IReplySessionChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplySessionChannel);
         }
         if ((type == typeof(IDuplexSessionChannel)) && binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IDuplexSessionChannel);
         }
     }
     for (int j = 0; j < supportedChannels.Length; j++)
     {
         System.Type type2 = supportedChannels[j];
         if ((type2 == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 IChannelListener<IInputSessionChannel> inner = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                 result = DatagramAdapter.GetInputListener(inner, throttle, binding);
             }
             return typeof(IInputSessionChannel);
         }
         if ((type2 == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 IChannelListener<IReplySessionChannel> listener2 = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                 result = DatagramAdapter.GetReplyListener(listener2, throttle, binding);
             }
             return typeof(IReplySessionChannel);
         }
         if ((supportContextSession && (type2 == typeof(IReplySessionChannel))) && (binding.CanBuildChannelListener<IReplyChannel>(parameters) && (binding.GetProperty<IContextSessionProvider>(parameters) != null)))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplyChannel);
         }
     }
     return null;
 }
 void EnsureQueuedDeliveryRequirements(string name, Binding binding)
 {
     if (QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.Required
         || QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.NotAllowed)
     {
         IBindingDeliveryCapabilities caps = binding.GetProperty<IBindingDeliveryCapabilities>(new BindingParameterCollection());
         if (caps == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                 SR.GetString(SR.SinceTheBindingForDoesnTSupportIBindingCapabilities2_1, name)));
         }
         else
         {
             bool queuedTransport = caps.QueuedDelivery;
             if (QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.Required && !queuedTransport)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                     SR.GetString(SR.BindingRequirementsAttributeRequiresQueuedDelivery1, name)));
             }
             else if (QueuedDeliveryRequirements == QueuedDeliveryRequirementsMode.NotAllowed && queuedTransport)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                     SR.GetString(SR.BindingRequirementsAttributeDisallowsQueuedDelivery1, name)));
             }
         }
     }
 }
 void EnsureOrderedDeliveryRequirements(string name, Binding binding)
 {
     if (RequireOrderedDelivery)
     {
         IBindingDeliveryCapabilities caps = binding.GetProperty<IBindingDeliveryCapabilities>(new BindingParameterCollection());
         if (caps == null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                 SR.GetString(SR.SinceTheBindingForDoesnTSupportIBindingCapabilities1_1, name)));
         }
         else
         {
             if (!caps.AssuresOrderedDelivery)
             {
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                     SR.GetString(SR.TheBindingForDoesnTSupportOrderedDelivery1, name)));
             }
         }
     }
 }