Example #1
0
        void TestInstanceBehavior(MessageInspectBehavior b, string expected, Result actual, int invocations)
        {
            ServiceHost h = new ServiceHost(typeof(AllActions), new Uri("http://localhost:8080"));

            try {
                h.AddServiceEndpoint(typeof(IAllActions).FullName, new BasicHttpBinding(), "AllActions");
                h.Description.Behaviors.Add(b);
                ServiceDebugBehavior db = h.Description.Behaviors.Find <ServiceDebugBehavior> ();
                db.IncludeExceptionDetailInFaults = true;
                h.Open();
                AllActionsProxy p = new AllActionsProxy(new BasicHttpBinding()
                {
                    SendTimeout = TimeSpan.FromSeconds(5), ReceiveTimeout = TimeSpan.FromSeconds(5)
                }, new EndpointAddress("http://localhost:8080/AllActions"));

                for (int i = 0; i < invocations; ++i)
                {
                    p.Get(10);
                }
                p.Close();

                //let ther server finish his work
                Thread.Sleep(100);
                Assert.AreEqual(expected, actual.string_res);
                actual.Done = true;
            }
            finally {
                h.Close();
            }
        }
        void TestInstanceBehavior(MessageInspectBehavior b, string expected, Result actual, int invocations)
        {
            ServiceHost h = new ServiceHost(typeof(AllActions), new Uri("http://localhost:8080"));

            try
            {
                h.AddServiceEndpoint(typeof(IAllActions).FullName, new BasicHttpBinding(), "AllActions");
                h.Description.Behaviors.Add(b);
                ServiceDebugBehavior db = h.Description.Behaviors.Find <ServiceDebugBehavior> ();
                db.IncludeExceptionDetailInFaults = true;
                h.Open();
                foreach (ChannelDispatcher cd in h.ChannelDispatchers)
                {
                    foreach (var ed in cd.Endpoints)
                    {
                        if (ed.ContractName == "IHttpGetHelpPageAndMetadataContract")
                        {
                            continue;
                        }
                        Assert.AreEqual(typeof(AllActions), ed.DispatchRuntime.Type, "Type property: " + ed.ContractName);
                    }
                }
                AllActionsProxy p = new AllActionsProxy(new BasicHttpBinding()
                {
                    SendTimeout = TimeSpan.FromSeconds(5), ReceiveTimeout = TimeSpan.FromSeconds(5)
                }, new EndpointAddress("http://localhost:8080/AllActions"));

                for (int i = 0; i < invocations; ++i)
                {
                    p.Get(10);
                }
                p.Close();

                //let ther server finish his work
                Thread.Sleep(100);
                Assert.AreEqual(expected, actual.string_res);
                actual.Done = true;
            }
            finally
            {
                h.Close();
            }
        }