Ejemplo n.º 1
0
        internal void WSHttpRequestReplyWithTransportMessageCertificateEchoString()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateHttpsWebHostBuilder <WSHttpTransportWithMessageCredentialWithCertificate>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.WSHttpBinding wsHttpBinding = ClientHelper.GetBufferedModeWSHttpBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                wsHttpBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Certificate;
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(wsHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/WSHttpWcfService/basichttp.svc")));
                ClientCredentials clientCredentials = (ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(ClientCredentials)];
                clientCredentials.ClientCertificate.Certificate = ServiceHelper.GetServiceCertificate();
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                ClientContract.IEchoService channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                ((IChannel)channel).Close();
                Console.WriteLine("read ");
            }
        }
Ejemplo n.º 2
0
        public void WSHttpRequestReplyWithTransportMessageEchoStringDemuxFailure()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateHttpsWebHostBuilder <WSHttpTransportWithMessageCredentialWithUserNameExpire>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.WSHttpBinding wsHttpBinding = ClientHelper.GetBufferedModeWSHttpBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                wsHttpBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.UserName;
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(wsHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/WSHttpWcfService/basichttp.svc")));
                ClientCredentials clientCredentials = (ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(ClientCredentials)];
                clientCredentials.UserName.UserName = "******";
                clientCredentials.UserName.Password = "******";
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                ClientContract.IEchoService channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                Thread.Sleep(6000);
                try
                {
                    channel.EchoString(testString);
                }catch (Exception ex)
                {
                    Assert.True(typeof(System.ServiceModel.FaultException).Equals(ex.InnerException.GetType()));
                    Assert.Contains("expired security context token", ex.InnerException.Message);
                }
            }
        }
Ejemplo n.º 3
0
        public void WSHttpRequestReplyWithTransportMessageEchoString()
        {
            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
            string testString = new string('a', 3000);
            var    host       = ServiceHelper.CreateHttpsWebHostBuilder <WSHttpTransportWithMessageCredentialWithUserName>(_output).Build();

            using (host)
            {
                host.Start();
                var wsHttpBinding = ClientHelper.GetBufferedModeWSHttpBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                wsHttpBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.UserName;
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(wsHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/WSHttpWcfService/basichttp.svc")));
                ClientCredentials clientCredentials = (ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(ClientCredentials)];
                clientCredentials.UserName.UserName = "******";
                clientCredentials.UserName.Password = "******";
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication();
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
                ClientContract.IEchoService channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                var result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                Thread.Sleep(5000);

                ((IChannel)channel).Close();
                Console.WriteLine("read ");
            }
        }
Ejemplo n.º 4
0
        public void NetHttpWebSocketsBufferedTransferMode()
        {
            string testString = new string('a', 3000);
            var    host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                System.ServiceModel.ChannelFactory <ClientContract.IEchoService> factory = null;
                ClientContract.IEchoService channel = null;
                host.Start();
                try
                {
                    var binding = ClientHelper.GetBufferedModeWebSocketBinding();
                    factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(binding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri(NetHttpBufferedServiceUri)));
                    channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    var result = channel.EchoString(testString);
                    Assert.Equal(testString, result);
                    ((IChannel)channel).Close();
                    factory.Close();
                }
                finally
                {
                    ServiceHelper.CloseServiceModelObjects((IChannel)channel, factory);
                }
            }
        }
Ejemplo n.º 5
0
        // [Fact, Description("transport-security-with-certificate-authentication")]
        //TODO set up in container, tested locally and this works
        public void WSHttpRequestReplyWithTransportMessageCertificateEchoString()
        {
            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
            string testString = new string('a', 3000);
            var    host       = ServiceHelper.CreateHttpsWebHostBuilder <WSHttpTransportWithMessageCredentialWithCertificate>(_output).Build();

            using (host)
            {
                host.Start();
                var wsHttpBinding = ClientHelper.GetBufferedModeWSHttpBinding(System.ServiceModel.SecurityMode.TransportWithMessageCredential);
                wsHttpBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.Certificate;
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(wsHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/WSHttpWcfService/basichttp.svc")));
                ClientCredentials clientCredentials = (ClientCredentials)factory.Endpoint.EndpointBehaviors[typeof(ClientCredentials)];
                clientCredentials.ClientCertificate.SetCertificate(
                    StoreLocation.LocalMachine,
                    StoreName.My, X509FindType.FindBySubjectName
                    , "birojtestcert"
                    );

                ClientContract.IEchoService channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                var result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                ((IChannel)channel).Close();
                Console.WriteLine("read ");
            }
        }
Ejemplo n.º 6
0
        public void BasicHttpsCustomBindingRequestReplyEchoString(bool useHttps)
        {
            string   testString = new string('a', 4000);
            IWebHost host       = ServiceHelper.CreateHttpsWebHostBuilder <StartupCustomBinding>(_output).Build();

            using (host)
            {
                string serviceUrl = (useHttps ? "https" : "http") + "://localhost:8443/BasicHttpWcfService/basichttp.svc";
                host.Start();
                System.ServiceModel.BasicHttpBinding BasicHttpBinding = ClientHelper.GetBufferedModeBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(BasicHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri(serviceUrl)));
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                try
                {
                    ClientContract.IEchoService channel = factory.CreateChannel();
                    ((IChannel)channel).Open();
                    string result = channel.EchoString(testString);
                    Assert.Equal(testString, result);
                    ((IChannel)channel).Close();
                }
                catch (Exception ex)
                {
                    Assert.True(!useHttps && ex.Message.Contains("The provided URI scheme 'http' is invalid"));
                }
            }
        }
Ejemplo n.º 7
0
        public void WSHttpRequestReplyEchoStringTransportSecurity()
        {
            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate);
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateHttpsWebHostBuilder <WSHttpTransportSecurityOnly>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.WSHttpBinding wsHttpBinding = ClientHelper.GetBufferedModeWSHttpBinding(System.ServiceModel.SecurityMode.Transport);
                wsHttpBinding.Security.Message.ClientCredentialType = System.ServiceModel.MessageCredentialType.None;
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(wsHttpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/WSHttpWcfService/basichttp.svc")));
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                ClientContract.IEchoService channel = factory.CreateChannel();
                ((IChannel)channel).Open();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                Console.WriteLine("read ");
                ((IChannel)channel).Close();
            }
        }
Ejemplo n.º 8
0
        public void EchoStringTest(Channels.MessageVersion messageVersion, System.ServiceModel.Channels.MessageVersion clientMessageVersion)
        {
            string testString     = new string('a', 10);
            var    webHostBuilder = ServiceHelper.CreateWebHostBuilder <Startup>(_output);

            webHostBuilder.ConfigureServices(services => services.AddServiceModelServices());
            webHostBuilder.Configure(app =>
            {
                app.UseServiceModel(builder =>
                {
                    builder.AddService <Services.EchoService>();
                    builder.AddServiceEndpoint <Services.EchoService, ServiceContract.IEchoService>(Startup.GetServerBinding(messageVersion), "/MessageVersionTest.svc");
                });
            });
            var host = webHostBuilder.Build();

            using (host)
            {
                host.Start();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(Startup.GetClientBinding(clientMessageVersion),
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/MessageVersionTest.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                var result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                ((System.ServiceModel.IClientChannel)channel).Close();
            }
        }
Ejemplo n.º 9
0
        public void BinaryMessageEncoderCompressionFormat_EchoString(Type startupType, System.ServiceModel.Channels.Binding clientBinding)
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder(_output, startupType).Build();

            using (host)
            {
                host.Start();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(clientBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/basichttp.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
            }
        }
Ejemplo n.º 10
0
        public void AccessDeniedForBasicHttpRequestReplyEcho()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpBinding httpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/basichttp.svc")));
                ClientContract.IEchoService   channel = factory.CreateChannel();
                SecurityAccessDeniedException ex      = Assert.Throws <SecurityAccessDeniedException>(() => channel.EchoToFail(testString));
                Assert.Equal("Access is denied.", ex.Message);
            }
        }
Ejemplo n.º 11
0
        public void BasicHttpRequestReplyEchoWithServiceBehavior()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpBinding httpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/basichttp.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
            }
        }
Ejemplo n.º 12
0
        public void HandleQuotesInContentTypeCharSet()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <StartupCharSetQuotes>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpBinding httpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/ITestBasicScenariosService.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                var result = channel.EchoString(testString);
                Assert.Equal(testString, result);
            }
        }
Ejemplo n.º 13
0
        public void EchoRoundtrip(Type startupType, System.ServiceModel.TransferMode clientTransferMode, int requestSize)
        {
            string   testString = new string('a', requestSize);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder(_output, startupType).Build();

            using (host)
            {
                host.Start();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(Startup.GetClientBinding(clientTransferMode),
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasicWcfService/basichttp.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                ((System.ServiceModel.Channels.IChannel)channel).Close();
                factory.Close();
            }
        }
Ejemplo n.º 14
0
        public void BasicHttpsRequestReplyEchoString()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateHttpsWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpsBinding httpsBinding = ClientHelper.GetBufferedModeHttpsBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpsBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("https://localhost:8443/BasicWcfService/basichttp.svc")));
                factory.Credentials.ServiceCertificate.SslCertificateAuthentication = new System.ServiceModel.Security.X509ServiceCertificateAuthentication
                {
                    CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None
                };
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
            }
        }
Ejemplo n.º 15
0
        public void BasicHttpRequestReplyEchoString()
        {
            string   testString = new string('a', 3000);
            IWebHost host       = ServiceHelper.CreateHttpSysBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpBinding httpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost/Temporary_Listen_Addresses/CoreWCFTestServices/BasicWcfService/basichttp.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                // Work around HttpSys host bug where it doesn't cancel a callback timer
                // and causes the host to write to the ILogger after the test has ended
                // which causes xunit to abort the test run. See dotnet/aspnetcore#30828
                var cts = new CancellationTokenSource();
                host.StopAsync(cts.Token).GetAwaiter().GetResult();
                cts.Cancel();
                cts.Dispose();
            }
        }
        public async Task VerifyPathRestoredAsync()
        {
            string   testString = new string('a', 100);
            IWebHost host       = ServiceHelper.CreateWebHostBuilder <Startup>(_output).Build();

            using (host)
            {
                host.Start();
                System.ServiceModel.BasicHttpBinding httpBinding = ClientHelper.GetBufferedModeBinding();
                var factory = new System.ServiceModel.ChannelFactory <ClientContract.IEchoService>(httpBinding,
                                                                                                   new System.ServiceModel.EndpointAddress(new Uri("http://localhost:8080/BasePath/BasicHttp/basichttp.svc")));
                ClientContract.IEchoService channel = factory.CreateChannel();
                string result = channel.EchoString(testString);
                Assert.Equal(testString, result);
                HttpClient httpClient      = new HttpClient();
                var        responseMessage = await httpClient.GetAsync("http://localhost:8080/BasePath/SomeOtherUrl/GetRequest");

                Assert.True(responseMessage.Headers.Contains("Test_Path"));
                Assert.Equal("/SomeOtherUrl/GetRequest", responseMessage.Headers.GetValues("Test_Path").SingleOrDefault());
                Assert.True(responseMessage.Headers.Contains("Test_PathBase"));
                Assert.Equal("/BasePath", responseMessage.Headers.GetValues("Test_PathBase").SingleOrDefault());
            }
        }