Exemple #1
0
        private void assertForCommon(string sourceString, IWebHost host)
        {
            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.Transport);
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath));
                    channel = factory.CreateChannel();

                    // ReSharper disable once SuspiciousTypeConversion.Global
                    ((IChannel)channel).Open();
                    string result = channel.EchoForPermission(sourceString);
                    Assert.Equal(sourceString, result);

                    //
                    // These were explicitly removed because the ServiceHelper already cleans these up, and
                    // in some cases not using proper disposal handling will result in:
                    // 'System.IO.IOException : Received an unexpected EOF or 0 bytes from the transport stream.'
                    // on the build server, causing false test failures.
                    //
                    // ((IChannel)channel).Close();
                    // factory.Close();
                }
                finally
                {
                    // ReSharper disable once SuspiciousTypeConversion.Global
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public void MultipleClientsUsingPooledSocket()
        {
            IWebHost host = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.NoSecurityRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    string clientIpEndpoint = channel.GetClientIpEndpoint();
                    ((IChannel)channel).Close();
                    for (int i = 0; i < 10; i++)
                    {
                        channel = factory.CreateChannel();
                        ((IChannel)channel).Open();
                        string clientIpEndpoint2 = channel.GetClientIpEndpoint();
                        Assert.Equal(clientIpEndpoint, clientIpEndpoint2);
                        ((IChannel)channel).Close();
                    }
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public void ConcurrentNetTcpClientConnection()
        {
            IWebHost host = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.NoSecurityRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    System.Threading.Tasks.Task <bool> resultTask = channel.WaitForSecondRequestAsync();
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                    channel.SecondRequest();
                    bool waitResult = resultTask.GetAwaiter().GetResult();
                    Assert.True(waitResult, $"SecondRequest wasn't executed concurrently");
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public void MessageContract()
        {
            IWebHost host = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.NoSecurityRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    var message = new ClientContract.TestMessage()
                    {
                        Header = "Header",
                        Body   = new MemoryStream(Encoding.UTF8.GetBytes("Hello world"))
                    };
                    ClientContract.TestMessage result = channel.TestMessageContract(message);
                    Assert.Equal("Header from server", result.Header);
                    Assert.Equal("Hello world from server", new StreamReader(result.Body, Encoding.UTF8).ReadToEnd());
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Exemple #5
0
        public static void MultipleClientsNonConcurrentNetTcpClientConnection()
        {
            string testString = new string('a', 3000);
            var    host       = CreateWebHostBuilder(new string[0]).Build();

            using (host)
            {
                host.Start();
                var binding = new System.ServiceModel.NetTcpBinding
                {
                    TransferMode = System.ServiceModel.TransferMode.Streamed
                };
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("net.tcp://localhost:8808/nettcp.svc")));
                var channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                var result = channel.EchoString(testString);
                ((IChannel)channel).Close();
                Assert.Equal(testString, result);
                channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                result = channel.EchoString(testString);
                ((IChannel)channel).Close();
                Assert.Equal(testString, result);
            }
        }
Exemple #6
0
 private void assertForCommon(string sourceString, IWebHost host)
 {
     using (host)
     {
         System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
         ClientContract.ITestService channel = null;
         host.Start();
         try
         {
             System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.Transport);
             factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                            new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath));
             channel = factory.CreateChannel();
             ((IChannel)channel).Open();
             string result = channel.EchoForPermission(sourceString);
             Assert.Equal(sourceString, result);
             ((IChannel)channel).Close();
             factory.Close();
         }
         finally
         {
             ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
         }
     }
 }
        public void MultipleClientsNonConcurrentNetTcpClientConnection()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.NoSecurityRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    string result = channel.EchoString(testString);
                    ((IChannel)channel).Close();
                    Assert.Equal(testString, result);
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    result = channel.EchoString(testString);
                    ((IChannel)channel).Close();
                    Assert.Equal(testString, result);
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Exemple #8
0
        public void SimpleNetTcpClientImpersonateUser()
        {
            string   sourceString = "test";
            IWebHost host         = ServiceHelper.CreateWebHostBuilder <ImpersonateCallerForAll>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.Transport);
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    string result = channel.EchoForImpersonation(sourceString);
                    Assert.Equal(sourceString, result);
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public void AuthorizationBasedonRolesTest()
        {
            string   testString = "a" + PrincipalPermissionMode.Always.ToString() + "test";
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <StartupForAuthorization>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.ITestService> factory = null;
                ClientContract.ITestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.Transport);
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    string result = channel.EchoForAuthorizarionOneRole(testString);
                    Assert.Equal(testString, result);
                    try
                    {
                        channel.EchoForAuthorizarionNoRole(testString);
                    }catch (Exception ex)
                    {
                        Assert.Contains("Access is denied", ex.Message);
                    }
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public async Task StreamedSynchronouslyCompletingTask()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <Contract.ITaskService> factory = null;
                Contract.ITaskService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetStreamedModeBinding();
                    factory = new System.ServiceModel.ChannelFactory <Contract.ITaskService>(binding,
                                                                                             new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.StreamedRelatveAddress));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    await channel.SynchronousCompletion();

                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
        public void DuplexEcho()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ServiceContract.IDuplexTestService> factory = null;
                ServiceContract.IDuplexTestService channel = null;
                host.Start();
                try
                {
                    System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding();
                    var callback = new ServiceContract.DuplexTestCallback();
                    factory = new System.ServiceModel.DuplexChannelFactory <ServiceContract.IDuplexTestService>(
                        new System.ServiceModel.InstanceContext(callback),
                        binding,
                        new System.ServiceModel.EndpointAddress(host.GetNetTcpAddressInUse() + Startup.DuplexRelativeAddress));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    var registerSuccess = channel.RegisterDuplexChannel();
                    Assert.True(registerSuccess, "Registration was not successful");
                    channel.SendMessage(testString);
                    Assert.Equal(1, callback.ReceivedMessages.Count);
                    Assert.Equal(testString, callback.ReceivedMessages[0]);
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Exemple #12
0
        public static void MultipleClientsUsingPooledSocket()
        {
            var host = CreateWebHostBuilder(new string[0]).Build();

            using (host)
            {
                host.Start();
                var binding = new System.ServiceModel.NetTcpBinding()
                {
                    OpenTimeout    = TimeSpan.FromMinutes(20),
                    CloseTimeout   = TimeSpan.FromMinutes(20),
                    SendTimeout    = TimeSpan.FromMinutes(20),
                    ReceiveTimeout = TimeSpan.FromMinutes(20)
                };
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("net.tcp://localhost:8808/nettcp.svc")));
                var channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                var clientIpEndpoint = channel.GetClientIpEndpoint();
                ((IChannel)channel).Close();
                for (int i = 0; i < 10; i++)
                {
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    var clientIpEndpoint2 = channel.GetClientIpEndpoint();
                    ((IChannel)channel).Close();
                    Assert.Equal(clientIpEndpoint, clientIpEndpoint2);
                }
            }
        }
Exemple #13
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.nettcp))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Exemple #14
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.GoodsService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("找不到名称为“{0}”的终结点。", endpointConfiguration));
 }
Exemple #15
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.NetTcpBinding_BeanTraderService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.Security.Transport.ClientCredentialType = System.ServiceModel.TcpClientCredentialType.Certificate;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Exemple #16
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.NetTcpBinding_IContract))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.Security.Mode          = System.ServiceModel.SecurityMode.None;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Не удалось найти конечную точку с именем \"{0}\".", endpointConfiguration));
 }
        private void BasicUserNameAuth(bool isError, string userName)
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <StartUpPermissionBaseForTC>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                binding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.UserName;
                UriBuilder uriBuilder = new UriBuilder(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath);
                uriBuilder.Host = "localhost"; // Replace 127.0.0.1 with localhost so Identity has correct value
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(uriBuilder.ToString()));
                System.ServiceModel.Description.ClientCredentials clientCredentials = (System.ServiceModel.Description.ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(System.ServiceModel.Description.ClientCredentials)];
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                clientCredentials.UserName.UserName = userName;
                clientCredentials.UserName.Password = RandomString(10);
                var channel = factory.CreateChannel();
                try
                {
                    if (isError)
                    {
                        Assert.ThrowsAny <System.ServiceModel.CommunicationException>(() =>
                        {
                            ((IChannel)channel).Open();
                        });

                        ((IChannel)channel).Abort();
                    }
                    else
                    {
                        ((IChannel)channel).Open();
                        string result = channel.EchoString(testString);
                        Assert.Equal(testString, result);
                        ((IChannel)channel).Close();
                        factory.Close();
                    }
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Exemple #18
0
        public static void ConcurrentNetTcpClientConnection()
        {
            string testString = new string('a', 3000);
            var    host       = CreateWebHostBuilder(new string[0]).Build();

            using (host)
            {
                host.Start();
                var binding = new System.ServiceModel.NetTcpBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("net.tcp://localhost:8808/nettcp.svc")));
                var channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                var resultTask = channel.WaitForSecondRequestAsync();
                Thread.Sleep(TimeSpan.FromSeconds(1));
                channel.SecondRequest();
                var waitResult = resultTask.GetAwaiter().GetResult();
                Assert.True(waitResult, $"SecondRequest wasn't executed concurrently");
            }
        }
Exemple #19
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.BasicHttpsBinding_IOnlineBankingSecurityCas))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpBinding_IOnlineBankingSecurityCas))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
        public void RemoteEndpointMessageProperty()
        {
            IWebHost host = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.NetTcpBinding nettcpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IRemoteEndpointMessageProperty>(nettcpBinding,
                                                                                                                     new System.ServiceModel.EndpointAddress(new Uri(host.GetNetTcpAddressInUse() + "/RemoteEndpointMessagePropertyService.svc")));
                ClientContract.IRemoteEndpointMessageProperty channel = factory.CreateChannel();

                Message request  = Message.CreateMessage(nettcpBinding.MessageVersion, "echo", "PASS");
                Message response = channel.Echo(request);

                string[] results = response.GetBody <string>().Split(';');
                Assert.Equal(3, results.Length);
                Assert.Equal("PASS", results[0]);

                string clientIP = results[1];
                CheckIP(clientIP);
                NetstatResults(results[2], host.GetNetTcpPortInUse().ToString());
            }
        }
        public async Task NetTCPRequestReplyWithTransportMessageEchoStringDemuxFailure()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <StartUpPermissionBaseForTCDemuxFailure>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.NetTcpBinding binding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                binding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.UserName;
                UriBuilder uriBuilder = new UriBuilder(host.GetNetTcpAddressInUse() + Startup.WindowsAuthRelativePath);
                uriBuilder.Host = "localhost"; // Replace 127.0.0.1 with localhost so Identity has correct value
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(uriBuilder.ToString()));
                System.ServiceModel.Description.ClientCredentials clientCredentials = (System.ServiceModel.Description.ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(System.ServiceModel.Description.ClientCredentials)];
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                clientCredentials.UserName.UserName = "******";
                clientCredentials.UserName.Password = RandomString(10);
                var channel = factory.CreateChannel();
                try
                {
                    ((IChannel)channel).Open();
                    await Task.Delay(6000);

                    string result = channel.EchoString(testString);
                }
                catch (Exception ex)
                {
                    Assert.IsAssignableFrom <System.ServiceModel.FaultException>(ex.InnerException);
                    Assert.Contains("expired security context token", ex.InnerException.Message);
                }
            }
        }
Exemple #22
0
        public static void MessageContract()
        {
            var host = CreateWebHostBuilder(new string[0]).Build();

            using (host)
            {
                host.Start();
                var binding = new System.ServiceModel.NetTcpBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.ITestService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("net.tcp://localhost:8808/nettcp.svc")));
                var channel = factory.CreateChannel();
                ((IChannel)channel).Open();

                var message = new ClientContract.TestMessage()
                {
                    Header = "Header",
                    Body   = new MemoryStream(Encoding.UTF8.GetBytes("Hello world"))
                };
                var result = channel.TestMessageContract(message);
                ((IChannel)channel).Close();
                Assert.Equal("Header from server", result.Header);
                Assert.Equal("Hello world from server", new StreamReader(result.Body, Encoding.UTF8).ReadToEnd());
            }
        }
Exemple #23
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.defaultEndpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.defaultBasic))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.basicHttpEndpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.basicHttpsEndpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpsoap11Endpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpsoap12Endpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpbinaryEndpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpssoap11Endpoint))
     {
         System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.AllowCookies           = true;
         result.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.Transport;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.httpssoap12Endpoint))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
         httpsBindingElement.AllowCookies           = true;
         httpsBindingElement.MaxBufferSize          = int.MaxValue;
         httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpsBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.nettcpdefaultBinding))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.nettcpdefaultBinding1))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize          = int.MaxValue;
         result.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize = int.MaxValue;
         result.Security.Mode          = System.ServiceModel.SecurityMode.None;
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Exemple #24
0
 private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
 {
     if ((endpointConfiguration == EndpointConfiguration.NetHttpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetHttpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement();
         tcpBindingElement.MaxBufferSize          = int.MaxValue;
         tcpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(tcpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
         System.ServiceModel.Channels.TcpTransportBindingElement tcpBindingElement = new System.ServiceModel.Channels.TcpTransportBindingElement();
         tcpBindingElement.MaxBufferSize          = int.MaxValue;
         tcpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(tcpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize           = int.MaxValue;
         result.ReaderQuotas            = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize  = int.MaxValue;
         result.Security.Mode           = System.ServiceModel.SecurityMode.None;
         result.ReliableSession.Enabled = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.NetTcpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.NetTcpBinding result = new System.ServiceModel.NetTcpBinding();
         result.MaxBufferSize           = int.MaxValue;
         result.ReaderQuotas            = System.Xml.XmlDictionaryReaderQuotas.Max;
         result.MaxReceivedMessageSize  = int.MaxValue;
         result.Security.Mode           = System.ServiceModel.SecurityMode.None;
         result.ReliableSession.Enabled = true;
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpOrdered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpUnordered_WSReliableMessaging11_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         reliableBindingElement.Ordered = false;
         reliableBindingElement.ReliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.WSReliableMessaging11;
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpOrdered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     if ((endpointConfiguration == EndpointConfiguration.WSHttpUnordered_WSReliableMessagingFebruary2005_IWcfReliableService))
     {
         System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
         System.ServiceModel.Channels.ReliableSessionBindingElement reliableBindingElement = new System.ServiceModel.Channels.ReliableSessionBindingElement();
         result.Elements.Add(reliableBindingElement);
         System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
         result.Elements.Add(textBindingElement);
         System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
         httpBindingElement.AllowCookies           = true;
         httpBindingElement.MaxBufferSize          = int.MaxValue;
         httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
         result.Elements.Add(httpBindingElement);
         return(result);
     }
     throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
 }
Exemple #25
0
        /// <summary>
        /// Retuns the newly constructed and configured WCF bindig derived class instance of the specified type.
        /// </summary>
        /// <remarks>
        /// This function might get more important if other WCF bingis are supported.
        /// All settings to a specific binding shuld be made here.
        /// All binding are probably not needed.
        /// </remarks>
        /// <param name="endPoint">EndPoint entity containig iformation about, what type of binding to return and how to set it.</param>
        /// <returns>The new configured binding element.</returns>
        public static System.ServiceModel.Channels.Binding GetWCFBinding(EndPoint endPoint)
        {
            if (endPoint.RemotingMechanism == RemotingMechanism.TcpBinary)
                return null;

            System.ServiceModel.Channels.Binding ret = null;

            WCFBinding bindingEnum = endPoint.Binding;

            switch (bindingEnum)
            {
                #region BasicHttpBinding
                case WCFBinding.BasicHttpBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.BasicHttpBinding bhb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                bhb = new System.ServiceModel.BasicHttpBinding();
                                bhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                bhb.MaxReceivedMessageSize = Int32.MaxValue;
                                bhb.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                bhb = new System.ServiceModel.BasicHttpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = bhb;
                        break;
                    }
                #endregion
                #region MsmqIntegrationBinding
                case WCFBinding.MsmqIntegrationBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding mib = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                mib = new System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding();
                                mib.Security.Mode = System.ServiceModel.MsmqIntegration.MsmqIntegrationSecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                mib = new System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = mib;
                        break;
                    }
                #endregion
                #region NetMsmqBinding
                case WCFBinding.NetMsmqBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.NetMsmqBinding nmb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                nmb = new System.ServiceModel.NetMsmqBinding();
                                nmb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                nmb.Security.Mode = System.ServiceModel.NetMsmqSecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                nmb = new System.ServiceModel.NetMsmqBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = nmb;
                        break;
                    }
                #endregion
                #region NetNamedPipeBinding
                case WCFBinding.NetNamedPipeBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.NetNamedPipeBinding nnpb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                nnpb = new System.ServiceModel.NetNamedPipeBinding();
                                nnpb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                nnpb.Security.Mode = System.ServiceModel.NetNamedPipeSecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                nnpb = new System.ServiceModel.NetNamedPipeBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = nnpb;
                        break;
                    }
                #endregion
                #region NetPeerTcpBinding
                case WCFBinding.NetPeerTcpBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.NetPeerTcpBinding nptb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                nptb = new System.ServiceModel.NetPeerTcpBinding();
                                nptb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                nptb.Security.Mode = System.ServiceModel.SecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                nptb = new System.ServiceModel.NetPeerTcpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = nptb;
                        break;
                    }
                #endregion
                #region NetTcpBinding
                case WCFBinding.NetTcpBinding:
                    {
                        System.ServiceModel.NetTcpBinding ntb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                ntb = new System.ServiceModel.NetTcpBinding();
                                ntb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                ntb.MaxReceivedMessageSize = Int32.MaxValue;
                                ntb.Security.Mode = System.ServiceModel.SecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                ntb = new System.ServiceModel.NetTcpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = ntb;
                        break;
                    }
                #endregion
                #region WSDualHttpBinding
                case WCFBinding.WSDualHttpBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.WSDualHttpBinding wdhb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                wdhb = new System.ServiceModel.WSDualHttpBinding();
                                wdhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                wdhb.Security.Mode = System.ServiceModel.WSDualHttpSecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                wdhb = new System.ServiceModel.WSDualHttpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = wdhb;
                        break;
                    }
                #endregion
                #region WSFederationHttpBinding
                case WCFBinding.WSFederationHttpBinding:
                    {
                        //WARNING: untested code
                        System.ServiceModel.WSFederationHttpBinding wfhb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                wfhb = new System.ServiceModel.WSFederationHttpBinding();
                                wfhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                wfhb = new System.ServiceModel.WSFederationHttpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = wfhb;
                        break;
                    }
                #endregion
                #region WSHttpBinding
                case WCFBinding.WSHttpBinding:
                    {
                        System.ServiceModel.WSHttpBinding whb = null;
                        switch (endPoint.BindingSettingType)
                        {
                            case WCFBindingSettingType.Default:
                                whb = new System.ServiceModel.WSHttpBinding();
                                whb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                                whb.MaxReceivedMessageSize = Int32.MaxValue;
                                whb.Security.Mode = System.ServiceModel.SecurityMode.None;
                                break;
                            case WCFBindingSettingType.UseConfigFile:
                                whb = new System.ServiceModel.WSHttpBinding(endPoint.BindingConfigurationName);
                                break;
                        }
                        ret = whb;
                        break;
                    }
                #endregion
            }

            return ret;
        }
Exemple #26
0
        /// <summary>
        /// Retuns the newly constructed and configured WCF bindig derived class instance of the specified type.
        /// </summary>
        /// <remarks>
        /// This function might get more important if other WCF bingis are supported.
        /// All settings to a specific binding shuld be made here.
        /// All binding are probably not needed.
        /// </remarks>
        /// <param name="endPoint">EndPoint entity containig iformation about, what type of binding to return and how to set it.</param>
        /// <returns>The new configured binding element.</returns>
        public static System.ServiceModel.Channels.Binding GetWCFBinding(EndPoint endPoint)
        {
            if (endPoint.RemotingMechanism == RemotingMechanism.TcpBinary)
            {
                return(null);
            }

            System.ServiceModel.Channels.Binding ret = null;

            WCFBinding bindingEnum = endPoint.Binding;

            switch (bindingEnum)
            {
                #region BasicHttpBinding
            case WCFBinding.BasicHttpBinding:
            {
                //WARNING: untested code
                System.ServiceModel.BasicHttpBinding bhb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    bhb = new System.ServiceModel.BasicHttpBinding();
                    bhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    bhb.MaxReceivedMessageSize = Int32.MaxValue;
                    bhb.Security.Mode          = System.ServiceModel.BasicHttpSecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    bhb = new System.ServiceModel.BasicHttpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = bhb;
                break;
            }

                #endregion
                #region MsmqIntegrationBinding
            case WCFBinding.MsmqIntegrationBinding:
            {
                //WARNING: untested code
                System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding mib = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    mib = new System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding();
                    mib.Security.Mode = System.ServiceModel.MsmqIntegration.MsmqIntegrationSecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    mib = new System.ServiceModel.MsmqIntegration.MsmqIntegrationBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = mib;
                break;
            }

                #endregion
                #region NetMsmqBinding
            case WCFBinding.NetMsmqBinding:
            {
                //WARNING: untested code
                System.ServiceModel.NetMsmqBinding nmb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    nmb = new System.ServiceModel.NetMsmqBinding();
                    nmb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    nmb.Security.Mode = System.ServiceModel.NetMsmqSecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    nmb = new System.ServiceModel.NetMsmqBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = nmb;
                break;
            }

                #endregion
                #region NetNamedPipeBinding
            case WCFBinding.NetNamedPipeBinding:
            {
                //WARNING: untested code
                System.ServiceModel.NetNamedPipeBinding nnpb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    nnpb = new System.ServiceModel.NetNamedPipeBinding();
                    nnpb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    nnpb.Security.Mode = System.ServiceModel.NetNamedPipeSecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    nnpb = new System.ServiceModel.NetNamedPipeBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = nnpb;
                break;
            }

                #endregion
                #region NetPeerTcpBinding
            case WCFBinding.NetPeerTcpBinding:
            {
                //WARNING: untested code
                System.ServiceModel.NetPeerTcpBinding nptb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    nptb = new System.ServiceModel.NetPeerTcpBinding();
                    nptb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    nptb.Security.Mode = System.ServiceModel.SecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    nptb = new System.ServiceModel.NetPeerTcpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = nptb;
                break;
            }

                #endregion
                #region NetTcpBinding
            case WCFBinding.NetTcpBinding:
            {
                System.ServiceModel.NetTcpBinding ntb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    ntb = new System.ServiceModel.NetTcpBinding();
                    ntb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    ntb.MaxReceivedMessageSize = Int32.MaxValue;
                    ntb.Security.Mode          = System.ServiceModel.SecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    ntb = new System.ServiceModel.NetTcpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = ntb;
                break;
            }

                #endregion
                #region WSDualHttpBinding
            case WCFBinding.WSDualHttpBinding:
            {
                //WARNING: untested code
                System.ServiceModel.WSDualHttpBinding wdhb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    wdhb = new System.ServiceModel.WSDualHttpBinding();
                    wdhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    wdhb.Security.Mode = System.ServiceModel.WSDualHttpSecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    wdhb = new System.ServiceModel.WSDualHttpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = wdhb;
                break;
            }

                #endregion
                #region WSFederationHttpBinding
            case WCFBinding.WSFederationHttpBinding:
            {
                //WARNING: untested code
                System.ServiceModel.WSFederationHttpBinding wfhb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    wfhb = new System.ServiceModel.WSFederationHttpBinding();
                    wfhb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    wfhb = new System.ServiceModel.WSFederationHttpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = wfhb;
                break;
            }

                #endregion
                #region WSHttpBinding
            case WCFBinding.WSHttpBinding:
            {
                System.ServiceModel.WSHttpBinding whb = null;
                switch (endPoint.BindingSettingType)
                {
                case WCFBindingSettingType.Default:
                    whb = new System.ServiceModel.WSHttpBinding();
                    whb.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
                    whb.MaxReceivedMessageSize = Int32.MaxValue;
                    whb.Security.Mode          = System.ServiceModel.SecurityMode.None;
                    break;

                case WCFBindingSettingType.UseConfigFile:
                    whb = new System.ServiceModel.WSHttpBinding(endPoint.BindingConfigurationName);
                    break;
                }
                ret = whb;
                break;
            }
                #endregion
            }


            return(ret);
        }