예제 #1
0
        public void CreateMexHttpsBinding()
        {
            var b = MetadataExchangeBindings.CreateMexHttpsBinding() as WSHttpBinding;

            Assert.IsNotNull(b, "#1");
            Assert.AreEqual(SecurityMode.Transport, b.Security.Mode, "#2");
            Assert.IsFalse(b.TransactionFlow, "#3");
            Assert.IsFalse(b.ReliableSession.Enabled, "#4");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is SecurityBindingElement), "#b1");
            Assert.IsTrue(b.CreateBindingElements().Any(be => be is TransactionFlowBindingElement), "#b2");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is ReliableSessionBindingElement), "#b3");
            Assert.IsTrue(new TransactionFlowBindingElement().TransactionProtocol == TransactionProtocol.Default, "#x1");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.MessageVersion, "#5");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.GetProperty <MessageVersion>(new BindingParameterCollection()), "#6");
            Assert.AreEqual(Uri.UriSchemeHttps, b.Scheme, "#8");

            var host = new ServiceHost(typeof(MetadataExchange));

            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), "https://localhost:" + NetworkHelpers.FindFreePort());
            host.Open();
            try
            {
                // it still does not rewrite MessageVersion.None. It's rather likely ServiceMetadataExtension which does overwriting.
                Assert.AreEqual(MessageVersion.Soap12WSAddressing10, ((ChannelDispatcher)host.ChannelDispatchers[0]).MessageVersion, "#7");
            }
            finally
            {
                host.Close();
            }
        }
예제 #2
0
        public void UserContextProperties()
        {
            var ch = ChannelFactory <IFooChannel> .CreateChannel(new BasicHttpBinding(), new EndpointAddress ("http://localhost:" + NetworkHelpers.FindFreePort()));

            var o = new OperationContext(ch);

            // FIXME: this is strange. It should return non-null value.
            // Assert.IsNull(o.Channel, "#1");

            Assert.IsNull(o.EndpointDispatcher, "#2");
            Assert.IsNull(o.Host, "#3");

            Assert.IsFalse(o.HasSupportingTokens, "#4");

            Assert.IsNull(o.IncomingMessageHeaders, "#5");
            Assert.IsNull(o.IncomingMessageProperties, "#6");
            Assert.IsNotNull(o.OutgoingMessageHeaders, "#7");
            Assert.IsNotNull(o.OutgoingMessageProperties, "#8");

            Assert.IsNull(o.InstanceContext, "#9");
            Assert.IsTrue(o.IsUserContext, "#10");
            Assert.IsNull(o.RequestContext, "#11");
            Assert.IsNull(o.ServiceSecurityContext, "#12");
            Assert.IsNull(o.SessionId, "#13");
            Assert.IsNull(o.SupportingTokens, "#14");
        }
예제 #3
0
        void RunClient()
        {
            var binding       = new BasicHttpBinding();
            var remoteAddress = new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort() + "/Service1");

            var normalClient     = new Service1Client(binding, remoteAddress);
            var collectionClient = new Service1Client(binding, remoteAddress);
            var nestedClient     = new Service1Client(binding, remoteAddress);
            var dbClient         = new Service1Client(binding, remoteAddress);

            var waits = new ManualResetEvent [4];

            for (int i = 0; i < waits.Length; i++)
            {
                waits [i] = new ManualResetEvent(false);
            }

            int passed = 0;

            normalClient.GetDataCompleted += delegate(object o, GetDataCompletedEventArgs e) {
                if (e.Error != null)
                {
                    Assert.Fail("Normal failed; error: {0}", e.Error);
                    throw e.Error;
                }
                Assert.AreEqual("A", ((DataType1)e.Result).Id, "Normal");
                Interlocked.Increment(ref passed);
                waits [0].Set();
            };
            normalClient.GetDataAsync();

            collectionClient.GetCollectionDataCompleted += delegate(object sender, GetCollectionDataCompletedEventArgs e) {
                if (e.Error != null)
                {
                    Assert.Fail("Collection failed; error: {0}", e.Error);
                    throw e.Error;
                }
                Assert.AreEqual("B,C", ItemsToString(e.Result.Cast <DataType1> ()), "Collection");
                Interlocked.Increment(ref passed);
                waits [1].Set();
            };
            collectionClient.GetCollectionDataAsync();

            nestedClient.GetNestedDataCompleted += delegate(object sender, GetNestedDataCompletedEventArgs e) {
                if (e.Error != null)
                {
                    Assert.Fail("Nested failed; error: {0}", e.Error);
                    throw e.Error;
                }
                Assert.AreEqual("D,E", ItemsToString(e.Result.Items.Cast <DataType1> ()), "Nested");
                Interlocked.Increment(ref passed);
                waits [2].Set();
            };
            nestedClient.GetNestedDataAsync();

            dbClient.JSMGetDatabasesCompleted += delegate(object sender, JSMGetDatabasesCompletedEventArgs e) {
                waits [3].Set();
                if (e.Error != null)
                {
                    throw e.Error;
                }
                Assert.AreEqual("databases", e.Result, "Databases");
                Interlocked.Increment(ref passed);
            };
            dbClient.JSMGetDatabasesAsync();

            WaitHandle.WaitAll(waits, TimeSpan.FromMinutes(1));
            if (passed != waits.Length)
            {
                Assert.Fail("Not all tests passed!");
            }
        }
예제 #4
0
        public void NonEndorsibleParameterInEndorsingSupport()
        {
            SymmetricSecurityBindingElement be =
                new SymmetricSecurityBindingElement();

            be.ProtectionTokenParameters =
                new X509SecurityTokenParameters();
            be.EndpointSupportingTokenParameters.Endorsing.Add(
                new UserNameSecurityTokenParameters());
            Binding          b      = new CustomBinding(be, new HttpTransportBindingElement());
            X509Certificate2 cert   = new X509Certificate2("Test/Resources/test.pfx", "mono");
            EndpointAddress  ea     = new EndpointAddress(new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), new X509CertificateEndpointIdentity(cert));
            CalcProxy        client = new CalcProxy(b, ea);

            client.ClientCredentials.UserName.UserName = "******";
            client.Sum(1, 2);
        }
예제 #5
0
        [Category("NotWorking")]          // Bug #5742
        public void HasEntityBody()
        {
            HttpListenerContext ctx;
            HttpListenerRequest request;
            NetworkStream       ns;
            var          port     = NetworkHelpers.FindFreePort();
            HttpListener listener = HttpListener2Test.CreateAndStartListener(
                "http://127.0.0.1:" + port + "/HasEntityBody/");

            // POST with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#A");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // POST with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#B");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // POST with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "POST /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#C");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with no Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#D");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with non-zero Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#E");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with zero Content-Length
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#F");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // GET with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "GET /HasEntityBody HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#G");
            HttpListener2Test.Send(ctx.Response.OutputStream, "%%%OK%%%");

            // PUT with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "PUT /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#H");

            // PUT with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "PUT /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#I");

            // INVALID with non-zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 3\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#J");

            // INVALID with zero Content-Lenth
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 0\r\n\r\n123");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsFalse(request.HasEntityBody, "#K");

            // INVALID with chunked encoding
            ns = HttpListener2Test.CreateNS(port);
            HttpListener2Test.Send(ns, "INVALID /HasEntityBody/ HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n");
            ctx     = listener.GetContext();
            request = ctx.Request;
            Assert.IsTrue(request.HasEntityBody, "#L");

            listener.Close();
        }
예제 #6
0
        public void ImpersonateCallerWithNoValidOperation()
        {
            ServiceHost host = new ServiceHost(typeof(TestService));
            var         b    = host.Description.Behaviors.Find <ServiceAuthorizationBehavior> ();

            b.ImpersonateCallerForAllOperations = true;
            b.PrincipalPermissionMode           = PrincipalPermissionMode.None;

            host.AddServiceEndpoint(typeof(TestService), new BasicHttpBinding(), new Uri("http://localhost:" + NetworkHelpers.FindFreePort()));

            host.Open();
        }
예제 #7
0
        public void RelativeListenUriWithBaseAddress()
        {
            // MyBindingElement overrides GetProperty<T>() to call GetInnerProperty<T>() (default implementation).
            // HttpTransportBindingElement should return Soap11.
            ServiceHost host = new ServiceHost(typeof(FooService), new Uri("http://localhost:" + NetworkHelpers.FindFreePort()));

            host.AddServiceEndpoint(typeof(IFooService),
                                    new CustomBinding(new MyBindingElement(true), new HttpTransportBindingElement()),
                                    "http://localhost:" + NetworkHelpers.FindFreePort(), new Uri("foobar", UriKind.Relative));
            host.Open();
            host.Close();
        }
예제 #8
0
        public void EndpointAddressAndViaMustMatchOnAddressingNone()
        {
            try {
                var ch = ChannelFactory <IFoo> .CreateChannel(new BasicHttpBinding(), new EndpointAddress ("http://localhost:" + NetworkHelpers.FindFreePort() + "/"), new Uri ("http://localhost:" + NetworkHelpers.FindFreePort() + "/HogeService"));

                ((ICommunicationObject)ch).Close();
            } catch (TargetInvocationException) {
                // we throw this exception so far. Since it is
                // very internal difference (channel is created
                // inside ClientRuntimeChannel.ctor() while .NET
                // does it in ChannelFactory<T>.CreateChannel(),
                // there is no point of treating it as failure).
                throw new ArgumentException();
            }
        }
예제 #9
0
        // It is almost identical to http-low-level-binding
        public void LowLevelHttpConnection()
        {
            HttpTransportBindingElement lel =
                new HttpTransportBindingElement();

            // Service
            BindingContext lbc = new BindingContext(
                new CustomBinding(),
                new BindingParameterCollection(),
                new Uri("http://localhost:" + NetworkHelpers.FindFreePort()),
                String.Empty, ListenUriMode.Explicit);

            listener = lel.BuildChannelListener <IReplyChannel> (lbc);

            try {
                listener.Open();

                svcret = "";

                Thread svc = new Thread(delegate() {
                    try {
                        svcret = LowLevelHttpConnection_SetupService();
                    } catch (Exception ex) {
                        svcret = ex.ToString();
                    }
                });
                svc.Start();

                // Client code goes here.

                HttpTransportBindingElement el =
                    new HttpTransportBindingElement();
                BindingContext ctx = new BindingContext(
                    new CustomBinding(),
                    new BindingParameterCollection());
                IChannelFactory <IRequestChannel> factory =
                    el.BuildChannelFactory <IRequestChannel> (ctx);

                factory.Open();

                IRequestChannel request = factory.CreateChannel(
                    new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort()));

                request.Open();

                try {
                    try {
                        Message reqmsg = Message.CreateMessage(
                            MessageVersion.Default, "Echo");
                        // sync version does not work here.
                        Message msg = request.Request(reqmsg, TimeSpan.FromSeconds(5));

                        using (XmlWriter w = XmlWriter.Create(TextWriter.Null)) {
                            msg.WriteMessage(w);
                        }

                        if (svcret != null)
                        {
                            Assert.Fail(svcret.Length > 0 ? svcret : "service code did not finish until this test expected.");
                        }
                    } finally {
                        if (request.State == CommunicationState.Opened)
                        {
                            request.Close();
                        }
                    }
                } finally {
                    if (factory.State == CommunicationState.Opened)
                    {
                        factory.Close();
                    }
                }
            } finally {
                if (listener.State == CommunicationState.Opened)
                {
                    listener.Close();
                }
            }
        }
        public void ServiceRecipientHasNoKeys()
        {
            AsymmetricSecurityBindingElement sbe =
                new AsymmetricSecurityBindingElement();

            sbe.InitiatorTokenParameters =
                new X509SecurityTokenParameters();
            sbe.RecipientTokenParameters =
                new UserNameSecurityTokenParameters();
            //sbe.SetKeyDerivation (false);
            //sbe.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
            CustomBinding binding = new CustomBinding(sbe,
                                                      new HttpTransportBindingElement());
            IChannelListener <IReplyChannel> l =
                binding.BuildChannelListener <IReplyChannel> (new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), new BindingParameterCollection());

            try {
                l.Open();
            } finally {
                if (l.State == CommunicationState.Opened)
                {
                    l.Close();
                }
            }
        }
예제 #11
0
 public MyListener()
     : base(IPAddress.Loopback, NetworkHelpers.FindFreePort())
 {
 }
        public void OpenBeforeDisplayInitializationUI()
        {
            var f = new FooProxy(new BasicHttpBinding(), new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort()));

            f.Endpoint.Contract.Behaviors.Add(new MyContractBehavior());
            f.Open();
        }
        public void NotAllowedInitializationUI()
        {
            var f = new FooProxy(new BasicHttpBinding(), new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort()));

            f.Endpoint.Contract.Behaviors.Add(new MyContractBehavior());
            f.InnerChannel.AllowInitializationUI = false;
            f.DisplayInitializationUI();
        }
예제 #14
0
        public void Current()
        {
            Assert.IsNull(OperationContext.Current, "Current-1");

            try {
                var ch = ChannelFactory <IFooChannel> .CreateChannel(new BasicHttpBinding(), new EndpointAddress ("http://localhost:" + NetworkHelpers.FindFreePort()));

                OperationContext.Current = new OperationContext(ch);
                Assert.IsNotNull(OperationContext.Current, "Current-2");
            }
            finally {
                OperationContext.Current = null;
                Assert.IsNull(OperationContext.Current, "Current-3");
            }
        }
예제 #15
0
 public void Setup()
 {
     socket = new ClientWebSocket();
     Port   = NetworkHelpers.FindFreePort();
 }
예제 #16
0
        public void ApplyDispatchBehavior()
        {
            // It cannot be applied to service endpoint dispatcher.
            IEndpointBehavior eb = new CallbackBehaviorAttribute()
            {
                ConcurrencyMode = ConcurrencyMode.Multiple, ValidateMustUnderstand = false
            };
            var cd = ContractDescription.GetContract(typeof(IFoo));
            var se = new ServiceEndpoint(cd);
            var ed = new EndpointDispatcher(new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort()), "IFoo", "urn:foo");

            eb.ApplyDispatchBehavior(se, ed);
        }
예제 #17
0
 public void SetUp()
 {
     port = NetworkHelpers.FindFreePort();
 }
예제 #18
0
        public void ApplyClientBehaviorNonDuplex()
        {
            // It must be applied to duplex callback runtime
            IEndpointBehavior eb = new CallbackBehaviorAttribute()
            {
                ConcurrencyMode = ConcurrencyMode.Multiple, ValidateMustUnderstand = false
            };
            var cd = ContractDescription.GetContract(typeof(IFoo));
            var se = new ServiceEndpoint(cd);
            var ed = new EndpointDispatcher(new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort()), "IFoo", "urn:foo");
            var cr = ed.DispatchRuntime.CallbackClientRuntime;

            eb.ApplyClientBehavior(se, cr);
        }
예제 #19
0
        public void ApplyBehavior()
        {
            ServiceHost host = new ServiceHost(typeof(TestService2));
            var         b    = host.Description.Behaviors.Find <ServiceAuthorizationBehavior> ();

            b.ImpersonateCallerForAllOperations = false;
            b.PrincipalPermissionMode           = PrincipalPermissionMode.None;

            host.AddServiceEndpoint(typeof(TestService2), new BasicHttpBinding(), new Uri("http://localhost:" + NetworkHelpers.FindFreePort()));

            host.Open();
            var ed = ((ChannelDispatcher)host.ChannelDispatchers [0]).Endpoints [0];
            var db = ed.DispatchRuntime;

            host.Close();

            Assert.IsFalse(db.ImpersonateCallerForAllOperations, "#1");
            Assert.AreEqual(PrincipalPermissionMode.None,
                            db.PrincipalPermissionMode, "#2");
        }
예제 #20
0
        void RunClient()
        {
            var binding       = new BasicHttpBinding();
            var remoteAddress = new EndpointAddress("http://localhost:" + NetworkHelpers.FindFreePort() + "/Service1");

            var normalClient     = new Service1Client(binding, remoteAddress);
            var collectionClient = new Service1Client(binding, remoteAddress);
            var nestedClient     = new Service1Client(binding, remoteAddress);
            var dbClient         = new Service1Client(binding, remoteAddress);

            {
                ManualResetEvent wait   = new ManualResetEvent(false);
                Exception        error  = null;
                object           result = null;

                normalClient.GetDataCompleted += delegate(object o, GetDataCompletedEventArgs e) {
                    try {
                        error  = e.Error;
                        result = e.Error == null ? e.Result : null;
                    } finally {
                        wait.Set();
                    }
                };
                normalClient.GetDataAsync();

                Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(20)), "#1 timeout");
                Assert.IsNull(error, "#1.1, inner exception: {0}", error);
                Assert.AreEqual("A", ((DataType1)result).Id, "#1.2");
            }

            {
                ManualResetEvent wait  = new ManualResetEvent(false);
                Exception        error = null;
                ObservableCollection <object> result = null;

                collectionClient.GetCollectionDataCompleted += delegate(object sender, GetCollectionDataCompletedEventArgs e) {
                    try {
                        error  = e.Error;
                        result = e.Error == null ? e.Result : null;
                    } finally {
                        wait.Set();
                    }
                };
                collectionClient.GetCollectionDataAsync();

                Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(20)), "#2 timeout");
                Assert.IsNull(error, "#2.1, inner exception: {0}", error);
                Assert.AreEqual("B,C", ItemsToString(result.Cast <DataType1> ()), "#2.2");
            }

            {
                ManualResetEvent wait  = new ManualResetEvent(false);
                Exception        error = null;
                WebServiceMoonlightTest.ServiceReference2.DataType2 result = null;

                nestedClient.GetNestedDataCompleted += delegate(object sender, GetNestedDataCompletedEventArgs e) {
                    try {
                        error  = e.Error;
                        result = e.Error == null ? e.Result : null;
                    } finally {
                        wait.Set();
                    }
                };
                nestedClient.GetNestedDataAsync();

                Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(20)), "#3 timeout");
                Assert.IsNull(error, "#3.1, inner exception: {0}", error);
                Assert.AreEqual("D,E", ItemsToString(result.Items.Cast <DataType1> ()), "#3.2");
            }

            {
                ManualResetEvent wait   = new ManualResetEvent(false);
                Exception        error  = null;
                string           result = null;

                dbClient.JSMGetDatabasesCompleted += delegate(object sender, JSMGetDatabasesCompletedEventArgs e) {
                    try {
                        error  = e.Error;
                        result = e.Error == null ? e.Result : null;
                    } finally {
                        wait.Set();
                    }
                };
                dbClient.JSMGetDatabasesAsync();

                Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(20)), "#4 timeout");
                Assert.IsNull(error, "#4.1, inner exception: {0}", error);
                Assert.AreEqual("databases", result, "#4.2");
            }
        }
예제 #21
0
        public void CheckDuplicateAuthenticatorTypesService()
        {
            SymmetricSecurityBindingElement be =
                new SymmetricSecurityBindingElement();

            be.ProtectionTokenParameters =
                new X509SecurityTokenParameters();
            be.EndpointSupportingTokenParameters.Endorsing.Add(
                new X509SecurityTokenParameters());
            // This causes multiple supporting token authenticator
            // of the same type.
            be.OptionalEndpointSupportingTokenParameters.Endorsing.Add(
                new X509SecurityTokenParameters());
            Binding            b    = new CustomBinding(be, new HttpTransportBindingElement());
            ServiceCredentials cred = new ServiceCredentials();

            cred.ServiceCertificate.Certificate =
                new X509Certificate2("Test/Resources/test.pfx", "mono");
            IChannelListener <IReplyChannel> ch = b.BuildChannelListener <IReplyChannel> (new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), cred);

            try {
                ch.Open();
            } finally {
                if (ch.State == CommunicationState.Closed)
                {
                    ch.Close();
                }
            }
        }
예제 #22
0
        public void InitializeRuntime3()
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService), CreateUri("http://localhost:" + NetworkHelpers.FindFreePort()))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "");
                host.Description.Behaviors.Find <ServiceDebugBehavior> ().HttpHelpPageEnabled = false;

                Assert.AreEqual(0, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #1");

                try {
                    host.Open();

                    Assert.AreEqual(1, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #2");
                } finally {
                    host.Close();
                }
            }
        }
        void AuthenticateClientAndServer(bool server, bool client)
        {
            IPEndPoint        endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), NetworkHelpers.FindFreePort());
            ClientServerState state    = new ClientServerState();

            state.Client   = new TcpClient();
            state.Listener = new TcpListener(endPoint);
            state.Listener.Start();
            state.ServerAuthenticated = new AutoResetEvent(false);
            state.ClientAuthenticated = new AutoResetEvent(false);
            state.ServerIOException   = !server;
            try {
                Thread serverThread = new Thread(() => StartServerAndAuthenticate(state));
                serverThread.Start();
                Thread clientThread = new Thread(() => StartClientAndAuthenticate(state, endPoint));
                clientThread.Start();
                Assert.AreEqual(server, state.ServerAuthenticated.WaitOne(TimeSpan.FromSeconds(5)),
                                "server not authenticated");
                Assert.AreEqual(client, state.ClientAuthenticated.WaitOne(TimeSpan.FromSeconds(5)),
                                "client not authenticated");
            } finally {
                if (state.ClientStream != null)
                {
                    state.ClientStream.Dispose();
                }
                state.Client.Close();
                if (state.ServerStream != null)
                {
                    state.ServerStream.Dispose();
                }
                if (state.ServerClient != null)
                {
                    state.ServerClient.Close();
                }
                state.Listener.Stop();
            }
        }
예제 #24
0
        public void InitializeRuntime1()
        {
            using (ServiceHost host = new ServiceHost(typeof(MyService), CreateUri("http://localhost:" + NetworkHelpers.FindFreePort()))) {
                host.AddServiceEndpoint(typeof(IMyContract), new BasicHttpBinding(), "e1");

                Assert.AreEqual(0, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #1");
                try {
                    host.Open();

                    Assert.AreEqual(2, host.ChannelDispatchers.Count, "ChannelDispatchers.Count #2");

                    ChannelDispatcher cd = (ChannelDispatcher)host.ChannelDispatchers [1];
                    Assert.AreEqual(1, cd.Endpoints.Count, "Endpoints.Count");
                    Assert.AreEqual("ServiceMetadataBehaviorHttpGetBinding", cd.BindingName, "BindingName");
                    Assert.AreEqual(host, cd.Host, "Host");
                    //Assert.AreEqual (false, cd.IsTransactedAccept, "IsTransactedAccept");
                    //Assert.AreEqual (false, cd.IsTransactedReceive, "IsTransactedReceive");

                    EndpointDispatcher ed = cd.Endpoints [0];
                    Assert.AreEqual(typeof(EndpointAddressMessageFilter), ed.AddressFilter.GetType(), "AddressFilter");
                    Assert.AreEqual(cd, ed.ChannelDispatcher, "ChannelDispatcher");
                    Assert.AreEqual(typeof(MatchAllMessageFilter), ed.ContractFilter.GetType(), "ContractFilter");
                    Assert.AreEqual("IHttpGetHelpPageAndMetadataContract", ed.ContractName, "ContractName");
                    Assert.AreEqual("http://schemas.microsoft.com/2006/04/http/metadata", ed.ContractNamespace, "ContractNamespace");
                    Assert.AreEqual(0, ed.FilterPriority, "FilterPriority");

                    EndpointAddress ea = ed.EndpointAddress;
                    // TODO

                    DispatchRuntime dr = ed.DispatchRuntime;
                    // TODO
                } finally {
                    host.Close();
                }
            }
        }
예제 #25
0
        public void Bug652331_3()
        {
            // Init service
            ServiceHost serviceHost = new ServiceHost(typeof(Service1), new Uri("http://localhost:" + NetworkHelpers.FindFreePort() + "/Service1"));

            serviceHost.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), string.Empty);

            // Enable metadata exchange (WSDL publishing)
            ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();

            mexBehavior.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(mexBehavior);
            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            serviceHost.Open();

            try {
                RunClient();
            } finally {
                serviceHost.Close();
            }
        }
        public void OtherParameterInEndorsingSupport()
        {
            SymmetricSecurityBindingElement be =
                new SymmetricSecurityBindingElement();

            be.ProtectionTokenParameters =
                new X509SecurityTokenParameters();
            be.EndpointSupportingTokenParameters.Endorsing.Add(
                new MyEndorsingTokenParameters());
            Binding         b      = new CustomBinding(be, new HttpTransportBindingElement());
            EndpointAddress ea     = new EndpointAddress(new Uri("http://localhost:" + NetworkHelpers.FindFreePort()), new X509CertificateEndpointIdentity(cert));
            CalcProxy       client = new CalcProxy(b, ea);

            client.Endpoint.Behaviors.RemoveAll <ClientCredentials> ();
            client.Endpoint.Behaviors.Add(new MyClientCredentials());
            client.Sum(1, 2);
        }