Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
        public void TestInstanceBehavior1()
        {
            Result res = new Result();
            MessageInspectBehavior b = new MessageInspectBehavior();

            b.instanceCtxInitializer = new MyInstanceContextInitializer(res);
            b.instanceCtxProvider    = new MyInstanceContextProvider(null, res);
            //b.instanceProvider = new MyInstanceProvider (null, res);
            b.msgInspect = new MyMessageInspector(res);
            string expected = "GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , IsIdle , OperationContext , InstanceContext = Opened , NotifyIdle , OperationContext , InstanceContext = Opened , ";

            TestInstanceBehavior(b, expected, res, 1);
            Assert.IsTrue(res.Done, "done");
        }
        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();
            }
        }