public static ISecurityCapabilities CreateISecurityCapabilities(BindingElement bindingElement)
    {
        CustomBinding binding = new CustomBinding(bindingElement);
        BindingParameterCollection collection = new BindingParameterCollection();
        BindingContext             context    = new BindingContext(binding, collection);
        ISecurityCapabilities      capability = binding.GetProperty <ISecurityCapabilities>(collection);

        return(capability);
    }
Esempio n. 2
0
        public static void Snippet15()
        {
            // <Snippet15>
            CustomBinding binding = new CustomBinding();

            binding.Elements.Add(new HttpTransportBindingElement());
            BindingParameterCollection paramCollection = new BindingParameterCollection();

            binding.GetProperty <IReplyChannel>(paramCollection);
            // </Snippet15>
        }
Esempio n. 3
0
        static void ReceiveSessionMessages()
        {
            // Read messages from queue until queue is empty:
            Console.WriteLine("Reading messages from queue {0}...", SampleManager.SessionQueueName);
            Console.WriteLine("Receiver Type: PeekLock");

            // Create listener and channel using custom binding
            CustomBinding   customBinding = new CustomBinding("customBinding");
            EndpointAddress address       = SampleManager.GetEndpointAddress(SampleManager.SessionQueueName, serviceBusNamespace);
            TransportClientEndpointBehavior securityBehavior = new TransportClientEndpointBehavior();

            securityBehavior.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(serviceBusKeyName, serviceBusKey);
            customBinding.GetProperty <IReceiveContextSettings>(new BindingParameterCollection()).Enabled = true;

            IChannelListener <IInputSessionChannel> inputSessionChannelListener = null;

            try
            {
                inputSessionChannelListener = customBinding.BuildChannelListener <IInputSessionChannel>(address.Uri, securityBehavior);
                inputSessionChannelListener.Open();

                while (true)
                {
                    IInputSessionChannel inputSessionChannel = null;
                    try
                    {
                        // Create a new session channel for every new session available. If no more sessions available,
                        // then the operation throws a TimeoutException.
                        inputSessionChannel = inputSessionChannelListener.AcceptChannel(acceptSessionReceiverTimeout);
                        inputSessionChannel.Open();

                        // TryReceive operation returns true if message is available otherwise it returns false.
                        Message receivedMessage;
                        while (inputSessionChannel.TryReceive(receiveSessionMessageTimeout, out receivedMessage))
                        {
                            if (receivedMessage != null)
                            {
                                SampleManager.OutputMessageInfo("Receive", receivedMessage);

                                // Since the message body contains a serialized string one can access it like this:
                                //string soapBody = receivedMessage.GetBody<string>();

                                // Since the binding has ReceiveContext enabled, a manual complete operation is mandatory
                                // if the message was processed successfully.
                                ReceiveContext rc;
                                if (ReceiveContext.TryGet(receivedMessage, out rc))
                                {
                                    rc.Complete(TimeSpan.FromSeconds(10.0d));
                                }
                                else
                                {
                                    throw new InvalidOperationException("Receiver is in peek lock mode but receive context is not available!");
                                }
                            }
                            else
                            {
                                // This IInputSessionChannel doesn't have any more messages
                                break;
                            }
                        }

                        // Close session channel
                        inputSessionChannel.Close();
                        inputSessionChannel = null;
                    }
                    catch (TimeoutException)
                    {
                        break;
                    }
                    finally
                    {
                        if (inputSessionChannel != null)
                        {
                            inputSessionChannel.Abort();
                        }
                    }
                }

                // Close channel listener
                inputSessionChannelListener.Close();
            }
            catch (Exception)
            {
                if (inputSessionChannelListener != null)
                {
                    inputSessionChannelListener.Abort();
                }
                throw;
            }
        }