Ejemplo n.º 1
0
    public static void DefaultCtor_NetHttps_Echo_RoundTrips_String(NetHttpMessageEncoding messageEncoding)
    {
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding netHttpsBinding = new NetHttpsBinding();
            netHttpsBinding.MessageEncoding = messageEncoding;
            factory      = new ChannelFactory <IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding)));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.True(String.Equals(testString, result), String.Format("Expected result was {0}. Actual was {1}", testString, result));

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
    [Issue(1398, OS = OSID.AnyOSX)] // Cert installation on OSX does not work yet
    public static void IRequestChannel_Https_NetHttpsBinding()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        bool ssl_Available = SSL_Available();

        if (!root_Certificate_Installed ||
            !ssl_Available)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            Console.WriteLine("SSL_Available evaluated as {0}", ssl_Available);
            return;
        }
#endif
        IChannelFactory <IRequestChannel> factory = null;
        IRequestChannel channel      = null;
        Message         replyMessage = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);

            // Create the channel factory
            factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));

            // *** EXECUTE *** \\
            // Send the Message and receive the Response.
            replyMessage = channel.Request(requestMessage);

            // *** VALIDATE *** \\
            var    replyReader      = replyMessage.GetReaderAtBodyContents();
            string actualResponse   = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            Assert.Equal(expectedResponse, actualResponse);

            // *** CLEANUP *** \\
            replyMessage.Close();
            channel.Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(channel, factory);
        }
    }
Ejemplo n.º 3
0
        protected override Binding GetBinding()
        {
            var binding = new NetHttpsBinding();

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            return(binding);
        }
Ejemplo n.º 4
0
 public override Binding Configure(
     NetHttpsBinding binding)
 {
     // inherently session-full binding
     IncompatibleBinding(binding);
     return(binding);
 }
Ejemplo n.º 5
0
        public override Binding Configure(
            NetHttpsBinding binding)
        {
            base.Configure(binding);

            if (binding.MaxReceivedMessageSize == Constants.DefaultReceivedMessageSize)
            {
                binding.MaxReceivedMessageSize = Constants.MaxReceivedMessage;
            }

            binding.Security = new BasicHttpsSecurity
            {
                Mode      = BasicHttpsSecurityMode.Transport,
                Transport = new HttpTransportSecurity
                {
                    ClientCredentialType = HttpClientCredentialType.None,
                },
            };
            binding.ReliableSession = new OptionalReliableSession
            {
                Enabled = false,
                Ordered = false,
            };

            return(binding);
        }
Ejemplo n.º 6
0
    public static void NonDefaultCtor_NetHttps_Echo_RoundTrips_String()
    {
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding netHttpsBinding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);
            factory      = new ChannelFactory <IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps_Binary));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.NotNull(result);
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
Ejemplo n.º 7
0
    public static void TransportWithMessageCredential_NotSupported_NetHttps()
    {
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        // BasicHttpsSecurityMode.TransportWithMessageCredential is accessible but not supported.
        // Verify the correct exception and message is thrown.
        // When/if Message Security is supported this test will fail and will serve as a reminder to add test coverage.
        Assert.Throws <PlatformNotSupportedException>(() =>
        {
            try
            {
                // *** SETUP *** \\
                NetHttpsBinding netHttpsBinding = new NetHttpsBinding(BasicHttpsSecurityMode.TransportWithMessageCredential);
                factory      = new ChannelFactory <IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps_Binary));
                serviceProxy = factory.CreateChannel();

                // *** EXECUTE *** \\
                string result = serviceProxy.Echo(testString);
            }
            finally
            {
                // *** ENSURE CLEANUP *** \\
                ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
            }
        });
    }
Ejemplo n.º 8
0
        private Binding GetNetHttpBinding(NetHttpMessageEncoding encoding)
        {
            var binding = new NetHttpsBinding();

            binding.MessageEncoding = encoding;
            binding.Name            = Enum.GetName(typeof(NetHttpMessageEncoding), encoding);
            return(binding);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Configures the specified binding.
        /// </summary>
        /// <param name="binding">The binding.</param>
        /// <returns>Binding.</returns>
        public virtual Binding Configure(
            NetHttpsBinding binding)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            return(ConfigureDefault(binding));
        }
Ejemplo n.º 10
0
    public static void IDuplexSessionChannel_Https_NetHttpsBinding()
    {
        IChannelFactory <IDuplexSessionChannel> factory = null;
        IDuplexSessionChannel channel = null;
        Message replyMessage          = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);

            // Create the channel factory
            factory = binding.BuildChannelFactory <IDuplexSessionChannel>(new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttpsWebSockets));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));
            requestMessage.Headers.MessageId = new UniqueId(Guid.NewGuid());

            // *** EXECUTE *** \\
            // Send the Message and receive the Response.
            channel.Send(requestMessage);
            replyMessage = channel.Receive(TimeSpan.FromSeconds(5));

            // *** VALIDATE *** \\
            // If the incoming Message did not contain the same UniqueId used for the MessageId of the outgoing Message we would have received a Fault from the Service
            string expectedMessageID = requestMessage.Headers.MessageId.ToString();
            string actualMessageID   = replyMessage.Headers.RelatesTo.ToString();
            Assert.True(String.Equals(expectedMessageID, actualMessageID), String.Format("Expected Message ID was {0}. Actual was {1}", expectedMessageID, actualMessageID));

            // Validate the Response
            var    replyReader      = replyMessage.GetReaderAtBodyContents();
            string actualResponse   = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            Assert.Equal(expectedResponse, actualResponse);

            // *** CLEANUP *** \\
            replyMessage.Close();
            channel.Session.CloseOutputSession();
            channel.Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(channel, factory);
        }
    }
        protected override void OnApplyConfiguration(Binding binding)
        {
            base.OnApplyConfiguration(binding);
            NetHttpsBinding netHttpsBinding = (NetHttpsBinding)binding;

            netHttpsBinding.MessageEncoding = this.MessageEncoding;

            this.WebSocketSettings.ApplyConfiguration(netHttpsBinding.WebSocketSettings);
            this.ReliableSession.ApplyConfiguration(netHttpsBinding.ReliableSession);
            this.Security.ApplyConfiguration(netHttpsBinding.Security);
        }
        protected internal override void InitializeFrom(Binding binding)
        {
            base.InitializeFrom(binding);
            NetHttpsBinding netHttpsBinding = (NetHttpsBinding)binding;

            SetPropertyValueIfNotDefaultValue(ConfigurationStrings.MessageEncoding, netHttpsBinding.MessageEncoding);

            this.WebSocketSettings.InitializeFrom(netHttpsBinding.WebSocketSettings);
            this.ReliableSession.InitializeFrom(netHttpsBinding.ReliableSession);
            this.Security.InitializeFrom(netHttpsBinding.Security);
        }
Ejemplo n.º 13
0
        public override Binding Configure(
            NetHttpsBinding binding)
        {
            base.Configure(binding);

            binding.TransferMode           = TransferMode.Streamed;
            binding.MessageEncoding        = NetHttpMessageEncoding.Mtom;
            binding.MaxReceivedMessageSize = Constants.StreamingBasicHttpMaxMessageSize;
            binding.MaxBufferSize          = Constants.StreamingMaxBufferSize;

            return(binding);
        }
Ejemplo n.º 14
0
        public static void Main(string[] args)
        {
            Uri[] uriArray = new Uri[] {
                new Uri(Properties.Settings.Default.HTTPS_URL),
                new Uri(Properties.Settings.Default.HTTP_URL)
            };

            try
            {
                ServiceHost serviceHost = new ServiceHost(typeof(ImportService), uriArray);

                var netHttps_bind = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);
                netHttps_bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                netHttps_bind.MessageEncoding        = NetHttpMessageEncoding.Binary;
                netHttps_bind.MaxReceivedMessageSize = int.MaxValue;
                netHttps_bind.MaxBufferPoolSize      = int.MaxValue;
                netHttps_bind.MaxBufferSize          = int.MaxValue;

                var netHttp_bind = new NetHttpBinding(BasicHttpSecurityMode.None);
                //netHttp_bind.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                netHttp_bind.MessageEncoding        = NetHttpMessageEncoding.Binary;
                netHttp_bind.MaxReceivedMessageSize = int.MaxValue;
                netHttp_bind.MaxBufferPoolSize      = int.MaxValue;
                netHttp_bind.MaxBufferSize          = int.MaxValue;

                serviceHost.AddServiceEndpoint(typeof(IImport), netHttps_bind, "");
                serviceHost.AddServiceEndpoint(typeof(IImport), netHttp_bind, "");
                ServiceMetadataBehavior serviceMetadataBehavior = new ServiceMetadataBehavior()
                {
                    HttpGetEnabled  = true,
                    HttpsGetEnabled = true
                };
                serviceHost.Description.Behaviors.Add(serviceMetadataBehavior);
                serviceHost.Open();

                DateTime now = DateTime.Now;
                Console.WriteLine(string.Concat("Service is host at ", now.ToString()));
                Console.WriteLine("Host is running... Press <ESC> key to stop");
Read:
                var key = Console.ReadKey();
                if (key.Key != ConsoleKey.Escape)
                {
                    goto Read;
                }
                serviceHost.Close();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                Console.ReadLine();
            }
        }
Ejemplo n.º 15
0
        private static void ReadBindingSecurityConfiguration(ServiceEndpoint endPoint, StringBuilder endpointDetails)
        {
            if (endPoint.Binding is NetTcpBinding)
            {
                NetTcpBinding binding = endPoint.Binding as NetTcpBinding;

                endpointDetails.AppendLine(string.Format("Binding Security Mode: {0}", binding.Security.Mode.ToString()));
                if (binding.Security.Mode != SecurityMode.None)
                {
                    endpointDetails.AppendLine(string.Format("Transport Credential Type: {0}", binding.Security.Transport.ClientCredentialType.ToString()));
                    endpointDetails.AppendLine(string.Format("Transport Protection Level: {0}", binding.Security.Transport.ProtectionLevel.ToString()));
                    endpointDetails.AppendLine(string.Format("Message Credential Type: {0}", binding.Security.Message.ClientCredentialType.ToString()));
                }
            }

            if (endPoint.Binding is NetHttpBinding)
            {
                NetHttpBinding binding = endPoint.Binding as NetHttpBinding;

                endpointDetails.AppendLine(string.Format("Binding Security Mode: {0}", binding.Security.Mode.ToString()));
                if (binding.Security.Mode != BasicHttpSecurityMode.None)
                {
                    endpointDetails.AppendLine(string.Format("Transport Credential Type: {0}", binding.Security.Transport.ClientCredentialType.ToString()));
                    endpointDetails.AppendLine(string.Format("Message Credential Type: {0}", binding.Security.Message.ClientCredentialType.ToString()));
                }
            }

            if (endPoint.Binding is NetHttpsBinding)
            {
                NetHttpsBinding binding = endPoint.Binding as NetHttpsBinding;

                endpointDetails.AppendLine(string.Format("Binding Security Mode: {0}", binding.Security.Mode.ToString()));
                endpointDetails.AppendLine(string.Format("Transport Credential Type: {0}", binding.Security.Transport.ClientCredentialType.ToString()));
                endpointDetails.AppendLine(string.Format("Message Credential Type: {0}", binding.Security.Message.ClientCredentialType.ToString()));
            }

            if (endPoint.Binding is NetMsmqBinding)
            {
                NetMsmqBinding binding = endPoint.Binding as NetMsmqBinding;

                endpointDetails.AppendLine(string.Format("Binding Security Mode: {0}", binding.Security.Mode.ToString()));
                if (binding.Security.Mode != NetMsmqSecurityMode.None)
                {
                    endpointDetails.AppendLine(string.Format("Transport Credential Type: {0}", binding.Security.Transport.MsmqAuthenticationMode.ToString()));
                    endpointDetails.AppendLine(string.Format("Transport Protection Level: {0}", binding.Security.Transport.MsmqProtectionLevel.ToString()));
                    endpointDetails.AppendLine(string.Format("Message Credential Type: {0}", binding.Security.Message.ClientCredentialType.ToString()));
                }
            }
        }
Ejemplo n.º 16
0
        private Binding GetNetHttpsBinding(NetHttpMessageEncoding messageEncoding, TransferMode transferMode)
        {
            NetHttpsBinding binding = new NetHttpsBinding()
            {
                MaxReceivedMessageSize = SixtyFourMB,
                MaxBufferSize          = SixtyFourMB,
            };

            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode    = transferMode;
            binding.MessageEncoding = messageEncoding;
            binding.Name            = Enum.GetName(typeof(TransferMode), transferMode) +
                                      Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding);
            return(binding);
        }
Ejemplo n.º 17
0
    public static void WebSocket_Https_RequestReply_Buffered_KeepAlive(NetHttpMessageEncoding messageEncoding)
    {
        EndpointAddress endpointAddress;
        NetHttpsBinding binding = null;
        ChannelFactory <IWSRequestReplyService> channelFactory = null;
        IWSRequestReplyService client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpsBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage    = WebSocketTransportUsage.Always;
            binding.WebSocketSettings.KeepAliveInterval = TimeSpan.FromSeconds(2);
            binding.TransferMode    = TransferMode.Buffered;
            binding.MessageEncoding = messageEncoding;
            endpointAddress         = new EndpointAddress(Endpoints.WebSocketHttpsRequestReplyBuffered_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding));
            channelFactory          = new ChannelFactory <IWSRequestReplyService>(binding, endpointAddress);

            client = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking DownloadData
            string result = client.DownloadData();

            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // *** VALIDATE *** \\
            foreach (string serverLogItem in client.GetLog())
            {
                //Assert.True(serverLogItem != ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure, ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure);
                Assert.True(!ScenarioTestHelpers.IsLocalHost() || !serverLogItem.Contains(ScenarioTestHelpers.RemoteEndpointMessagePropertyFailure), serverLogItem);
            }

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
        public override Binding Configure(
            NetHttpsBinding binding)
        {
            base.Configure(binding);

            binding.Security = new BasicHttpsSecurity
            {
                Mode      = BasicHttpsSecurityMode.Transport,
                Transport = new HttpTransportSecurity
                {
                    ClientCredentialType = HttpClientCredentialType.None,
                },
            };

            return(binding);
        }
    public static void IRequestChannel_Https_NetHttpsBinding()
    {
        IChannelFactory <IRequestChannel> factory = null;
        IRequestChannel channel      = null;
        Message         replyMessage = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding binding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);

            // Create the channel factory
            factory = binding.BuildChannelFactory <IRequestChannel>(new BindingParameterCollection());
            factory.Open();

            // Create the channel.
            channel = factory.CreateChannel(new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps_Binary));
            channel.Open();

            // Create the Message object to send to the service.
            Message requestMessage = Message.CreateMessage(
                binding.MessageVersion,
                action,
                new CustomBodyWriter(clientMessage));

            // *** EXECUTE *** \\
            // Send the Message and receive the Response.
            replyMessage = channel.Request(requestMessage);

            // *** VALIDATE *** \\
            var    replyReader      = replyMessage.GetReaderAtBodyContents();
            string actualResponse   = replyReader.ReadElementContentAsString();
            string expectedResponse = "[client] This is my request.[service] Request received, this is my Reply.";
            Assert.Equal(expectedResponse, actualResponse);

            // *** CLEANUP *** \\
            replyMessage.Close();
            channel.Close();
            factory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects(channel, factory);
        }
    }
Ejemplo n.º 20
0
    public static void NonDefaultCtor_NetHttps_Echo_RoundTrips_String()
    {
#if FULLXUNIT_NOTSUPPORTED
        bool root_Certificate_Installed = Root_Certificate_Installed();
        bool ssl_Available = SSL_Available();

        if (!root_Certificate_Installed ||
            !ssl_Available)
        {
            Console.WriteLine("---- Test SKIPPED --------------");
            Console.WriteLine("Attempting to run the test in ToF, a ConditionalFact evaluated as FALSE.");
            Console.WriteLine("Root_Certificate_Installed evaluated as {0}", root_Certificate_Installed);
            Console.WriteLine("SSL_Available evaluated as {0}", ssl_Available);
            return;
        }
#endif
        string testString = "Hello";
        ChannelFactory <IWcfService> factory = null;
        IWcfService serviceProxy             = null;

        try
        {
            // *** SETUP *** \\
            NetHttpsBinding netHttpsBinding = new NetHttpsBinding(BasicHttpsSecurityMode.Transport);
            factory      = new ChannelFactory <IWcfService>(netHttpsBinding, new EndpointAddress(Endpoints.HttpBaseAddress_NetHttps));
            serviceProxy = factory.CreateChannel();

            // *** EXECUTE *** \\
            string result = serviceProxy.Echo(testString);

            // *** VALIDATE *** \\
            Assert.NotNull(result);
            Assert.Equal(testString, result);

            // *** CLEANUP *** \\
            factory.Close();
            ((ICommunicationObject)serviceProxy).Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
        }
    }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates the appropriate binding type for the given element
        /// </summary>
        /// <param name="endPoint">Enpoint to create binding object for</param>
        /// <returns>Binding represented in the config file</returns>
        private static Binding GetBinding(ChannelEndpointElement endPoint)
        {
            Binding binding = null;

            try
            {
                switch (endPoint.Binding)
                {
                case "basicHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new BasicHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new BasicHttpBinding();
                    }
                    break;

                case "basicHttpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new BasicHttpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new BasicHttpContextBinding();
                    }
                    break;

                case "customBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new CustomBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new CustomBinding();
                    }
                    break;

                case "netNamedPipeBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetNamedPipeBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetNamedPipeBinding();
                    }
                    break;

                case "netPeerTcpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetPeerTcpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetPeerTcpBinding();
                    }
                    break;

                case "netTcpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetTcpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetTcpBinding();
                    }
                    break;

                case "netTcpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetTcpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetTcpContextBinding();
                    }
                    break;

                case "webHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WebHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WebHttpBinding();
                    }
                    break;

                case "ws2007HttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WS2007HttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WS2007HttpBinding();
                    }
                    break;

                case "wsHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSHttpBinding();
                    }
                    break;

                case "wsHttpContextBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSHttpContextBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSHttpContextBinding();
                    }
                    break;

                case "wsDualHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSDualHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSDualHttpBinding();
                    }
                    break;

                case "wsFederationHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WSFederationHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WSFederationHttpBinding();
                    }
                    break;

                case "ws2007FederationHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new WS2007FederationHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new WS2007FederationHttpBinding();
                    }
                    break;

                case "msmqIntegrationBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new MsmqIntegrationBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new MsmqIntegrationBinding();
                    }
                    break;

                case "netMsmqBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetMsmqBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetMsmqBinding();
                    }
                    break;

                case "netHttpBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetHttpBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetHttpBinding();
                    }
                    break;

                case "netHttpsBinding":
                    if (!string.IsNullOrEmpty(endPoint.BindingConfiguration))
                    {
                        binding = new NetHttpsBinding(endPoint.BindingConfiguration);
                    }
                    else
                    {
                        binding = new NetHttpBinding();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "." + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name);
                throw ex;
            }

            return(binding);
        }
Ejemplo n.º 22
0
    public static void WebSocket_Https_Duplex_Streamed(NetHttpMessageEncoding messageEncoding)
    {
        string          endpointAddress;
        NetHttpsBinding binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService     client       = null;
        FlowControlledStream uploadStream = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpsBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode    = TransferMode.Streamed;
            binding.MessageEncoding = messageEncoding;

            clientReceiver  = new ClientReceiver();
            context         = new InstanceContext(clientReceiver);
            endpointAddress = Endpoints.WebSocketHttpsDuplexStreamed_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding);
            channelFactory  = new DuplexChannelFactory <IWSDuplexService>(context, binding, endpointAddress);
            client          = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            using (Stream stream = client.DownloadStream())
            {
                int readResult;
                // Read from the stream, 1000 bytes at a time.
                byte[] buffer = new byte[1000];
                do
                {
                    readResult = stream.Read(buffer, 0, buffer.Length);
                }while (readResult != 0);
            }

            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);

            client.UploadStream(uploadStream);
            client.StartPushingStream();
            // Wait for the callback to get invoked before telling the service to stop streaming.
            // This ensures we can read from the stream on the callback while the NCL layer at the service
            // is still writing the bytes from the stream to the wire.
            // This will deadlock if the transfer mode is buffered because the callback will wait for the
            // stream, and the NCL layer will continue to buffer the stream until it reaches the end.

            Assert.True(clientReceiver.ReceiveStreamInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the stream response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamInvoked.Reset();

            // Upload the stream while we are downloading a different stream
            uploadStream = new FlowControlledStream();
            uploadStream.ReadThrottle   = TimeSpan.FromMilliseconds(500);
            uploadStream.StreamDuration = TimeSpan.FromSeconds(1);
            client.UploadStream(uploadStream);

            client.StopPushingStream();
            // Waiting on ReceiveStreamCompleted from the ClientReceiver.
            Assert.True(clientReceiver.ReceiveStreamCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the stream response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveStreamCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                        "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
            clientReceiver.Dispose();
        }
    }
Ejemplo n.º 23
0
    public static void WebSocket_Https_Duplex_Buffered(NetHttpMessageEncoding messageEncoding)
    {
        EndpointAddress endpointAddress;
        NetHttpsBinding binding        = null;
        ClientReceiver  clientReceiver = null;
        InstanceContext context        = null;
        DuplexChannelFactory <IWSDuplexService> channelFactory = null;
        IWSDuplexService client = null;

        try
        {
            // *** SETUP *** \\
            binding = new NetHttpsBinding()
            {
                MaxReceivedMessageSize = ScenarioTestHelpers.SixtyFourMB,
                MaxBufferSize          = ScenarioTestHelpers.SixtyFourMB,
            };
            binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
            binding.TransferMode    = TransferMode.Buffered;
            binding.MessageEncoding = messageEncoding;

            clientReceiver  = new ClientReceiver();
            context         = new InstanceContext(clientReceiver);
            endpointAddress = new EndpointAddress(Endpoints.WebSocketHttpsDuplexBuffered_Address + Enum.GetName(typeof(NetHttpMessageEncoding), messageEncoding));
            channelFactory  = new DuplexChannelFactory <IWSDuplexService>(context, binding, endpointAddress);
            client          = channelFactory.CreateChannel();

            // *** EXECUTE *** \\
            // Invoking UploadData
            client.UploadData(ScenarioTestHelpers.CreateInterestingString(123));

            // Invoking StartPushingData
            client.StartPushingData();
            Assert.True(clientReceiver.ReceiveDataInvoked.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataInvoked.Reset();
            // Invoking StopPushingData
            client.StopPushingData();
            Assert.True(clientReceiver.ReceiveDataCompleted.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the buffered response from the Service to be completed. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));
            clientReceiver.ReceiveDataCompleted.Reset();

            // Getting results from server via callback.
            client.GetLog();
            Assert.True(clientReceiver.LogReceived.WaitOne(ScenarioTestHelpers.TestTimeout),
                        String.Format("Test case timeout was reached while waiting for the Logging from the Service to be received. Timeout was: {0}", ScenarioTestHelpers.TestTimeout));

            // *** VALIDATE *** \\
            Assert.True(clientReceiver.ServerLog.Count > 0,
                        "The logging done by the Server was not returned via the Callback.");

            // *** CLEANUP *** \\
            ((ICommunicationObject)client).Close();
            channelFactory.Close();
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)client, channelFactory);
        }
    }
Ejemplo n.º 24
0
 public override Binding Configure(
     NetHttpsBinding binding)
 {
     IncompatibleBinding(binding);
     return(binding);
 }