예제 #1
0
        public static void ServiceThrowsExceptionDetailsIncludedInFault()
        {
            string exceptionMessage    = "This is the exception message";
            string stackTraceTopMethod = "   at ErrorHandling.ThrowingService.Echo(String echo)";

            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <ThrowingDetailInFaultService, ISimpleService>(
                (services) =>
            {
                services.AddSingleton(new ThrowingDetailInFaultService(new Exception(exceptionMessage)));
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            ((System.ServiceModel.IClientChannel)channel).Open();
            System.ServiceModel.FaultException <System.ServiceModel.ExceptionDetail> exceptionThrown = Assert.Throws <System.ServiceModel.FaultException <System.ServiceModel.ExceptionDetail> >(() =>
            {
                _ = channel.Echo("hello");
            });
            Assert.NotNull(exceptionThrown);
            Assert.NotNull(exceptionThrown.Detail);
            Assert.True(exceptionThrown.Code.IsReceiverFault);
            System.ServiceModel.ExceptionDetail detail = exceptionThrown.Detail;
            Assert.Equal(exceptionMessage, detail.Message);
            Assert.StartsWith(stackTraceTopMethod, detail.StackTrace);
            Assert.Equal("InternalServiceFault", exceptionThrown.Code.SubCode.Name);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
        public void SimpleMethodOverloadTest()
        {
            ISimpleService service = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            service.GetOverloadedMethod(10).Should().Be(10);
            service.GetOverloadedMethod(10, 5).Should().Be(15);
        }
예제 #3
0
        public void ProxyDataAccessAndServiceLayer()
        {
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["DbProvider"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["SessionFactory"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["hibernateTransactionManager"]));
            Assert.IsFalse(AopUtils.IsAopProxy(ctx["transactionManager"]));
            //Assert.IsTrue(AopUtils.IsAopProxy(ctx["testObjectDaoTransProxy"]));
            Assert.IsTrue(AopUtils.IsAopProxy(ctx["TestObjectDao"]));
            Assert.IsTrue(AopUtils.IsAopProxy(ctx["SimpleService"]));

            CallCountingTransactionManager ccm = ctx["transactionManager"] as CallCountingTransactionManager;

            Assert.IsNotNull(ccm);
            Assert.AreEqual(0, ccm.begun);
            Assert.AreEqual(0, ccm.commits);

            LoggingAroundAdvice caa = ctx["loggingAroundAdvice"] as LoggingAroundAdvice;

            Assert.IsNotNull(caa);
            Assert.AreEqual(0, caa.numInvoked);

            ISimpleService simpleService = ctx["SimpleService"] as ISimpleService;

            Assert.IsNotNull(simpleService);
            simpleService.DoWork(new TestObject());
            Assert.AreEqual(1, ccm.begun);
            Assert.AreEqual(1, ccm.commits);
            Assert.AreEqual(1, caa.numInvoked);
        }
예제 #4
0
        public static void ReplacementMessageUsed()
        {
            string replacementEchoString = "bbbbb";
            var    inspector             = new MessageReplacingDispatchMessageInspector(replacementEchoString);
            var    behavior = new TestServiceBehavior {
                DispatchMessageInspector = inspector
            };
            var service = new DispatcherTestService();

            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <DispatcherTestService, ISimpleService>(
                (services) =>
            {
                services.AddSingleton <IServiceBehavior>(behavior);
                services.AddSingleton(service);
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();
            string         echo    = channel.Echo("hello");

            Assert.Equal(replacementEchoString, service.ReceivedEcho);
            Assert.Equal(replacementEchoString, echo);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
        public void RequestReply_TelemetryIsWritten()
        {
            TestTelemetryChannel.Clear();
            using (var host = new HostingContext <SimpleService, ISimpleService>())
            {
                host.Open();

                var            binding       = new NetTcpBinding();
                var            configuration = new TelemetryConfiguration();
                var            factory       = new ChannelFactory <ISimpleService>(binding, host.GetServiceAddress());
                ISimpleService channel       = null;
                try
                {
                    var behavior = new ClientTelemetryEndpointBehavior(configuration);
                    factory.Endpoint.EndpointBehaviors.Add(behavior);

                    channel = factory.CreateChannel();
                    channel.GetSimpleData();
                    ((IClientChannel)channel).Close();
                    factory.Close();

                    Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0, "No telemetry events written");
                }
                catch
                {
                    if (channel != null)
                    {
                        ((IClientChannel)channel).Abort();
                    }

                    factory.Abort();
                    throw;
                }
            }
        }
        public static void InstanceContextMode_PerCall()
        {
            PerCallInstanceContextSimpleServiceAndBehavior.ClearCounts();
            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <PerCallInstanceContextSimpleServiceAndBehavior, ISimpleService>(
                (services) =>
            {
                services.AddTransient <PerCallInstanceContextSimpleServiceAndBehavior>();
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            ((System.ServiceModel.Channels.IChannel)channel).Open();
            // Instance created as part of service startup to probe if type is availale in DI
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.CreationCount);
            // Instance not disposed as it implements IServiceBehavior and is added to service behaviors
            Assert.Equal(0, PerCallInstanceContextSimpleServiceAndBehavior.DisposalCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.AddBindingParametersCallCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.ApplyDispatchBehaviorCount);
            Assert.Equal(1, PerCallInstanceContextSimpleServiceAndBehavior.ValidateCallCount);

            PerCallInstanceContextSimpleServiceAndBehavior.ClearCounts();
            string echo = channel.Echo("hello");

            echo = channel.Echo("hello");
            PerCallInstanceContextSimpleServiceAndBehavior.WaitForDisposalCount(2, TimeSpan.FromSeconds(30));
            Assert.Equal(2, PerCallInstanceContextSimpleServiceAndBehavior.CreationCount);
            Assert.Equal(2, PerCallInstanceContextSimpleServiceAndBehavior.DisposalCount);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
예제 #7
0
        public static void ServiceThrowsTimeoutException()
        {
            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <ThrowingService, ISimpleService>(
                (services) =>
            {
                services.AddSingleton(new ThrowingService(new TimeoutException()));
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            System.ServiceModel.FaultException exceptionThrown = null;
            try
            {
                string echo = channel.Echo("hello");
            }
            catch (System.ServiceModel.FaultException e)
            {
                exceptionThrown = e;
            }

            Assert.NotNull(exceptionThrown);
            Assert.True(exceptionThrown.Code.IsReceiverFault);
            Assert.Equal("InternalServiceFault", exceptionThrown.Code.SubCode.Name);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
        public void BehaviorAddsCustomBinding()
        {
            using (var host = new HostingContext <SimpleService, ISimpleService>())
            {
                var            binding       = new NetTcpBinding();
                var            configuration = new TelemetryConfiguration();
                var            factory       = new ChannelFactory <ISimpleService>(binding, host.GetServiceAddress());
                ISimpleService channel       = null;
                try
                {
                    var behavior = new ClientTelemetryEndpointBehavior(configuration);
                    factory.Endpoint.EndpointBehaviors.Add(behavior);

                    channel = factory.CreateChannel();
                    var innerChannel = GetInnerChannel(channel);
                    ((IClientChannel)channel).Close();
                    factory.Close();

                    Assert.IsInstanceOfType(innerChannel, typeof(ClientTelemetryChannelBase), "Telemetry channel is missing");
                }
                catch
                {
                    factory.Abort();
                    if (channel != null)
                    {
                        ((IClientChannel)channel).Abort();
                    }

                    throw;
                }
            }
        }
        public void SimpleServiceMarshalingTest()
        {
            ISimpleService service = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            service.GetInt32().Should().Be(42);
            service.GetString().Should().Be("whatever");
        }
예제 #10
0
        public void ResponseIsTraced()
        {
            TraceTelemetryModule.Enable();
            try
            {
                TestTelemetryChannel.Clear();
                using (var host = new HostingContext <SimpleService, ISimpleService>())
                {
                    host.Open();
                    ISimpleService client = host.GetChannel();
                    client.GetSimpleData();
                }

                var trace = TestTelemetryChannel.CollectedData()
                            .OfType <EventTelemetry>()
                            .FirstOrDefault(x => x.Name == "WcfResponse");
                Assert.IsNotNull(trace, "No WcfResponse trace found");
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(trace.Properties["Body"]);
            }
            finally
            {
                TraceTelemetryModule.Disable();
            }
        }
        public static void InstanceContextMode_Single()
        {
            SingleInstanceContextSimpleService.ClearCounts();
            var serviceInstance = new SingleInstanceContextSimpleService();

            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <SingleInstanceContextSimpleService, ISimpleService>(
                (services) =>
            {
                services.AddSingleton(serviceInstance);
            });
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            ((System.ServiceModel.Channels.IChannel)channel).Open();
            Assert.Equal(1, SingleInstanceContextSimpleService.AddBindingParametersCallCount);
            Assert.Equal(1, SingleInstanceContextSimpleService.ApplyDispatchBehaviorCount);
            Assert.Equal(1, SingleInstanceContextSimpleService.ValidateCallCount);
            string echo = channel.Echo("hello");

            echo = channel.Echo("hello");
            Assert.Equal(1, SingleInstanceContextSimpleService.CreationCount);
            Assert.Equal(0, SingleInstanceContextSimpleService.DisposalCount);
            Assert.Equal(2, serviceInstance.CallCount);
            ((System.ServiceModel.Channels.IChannel)channel).Close();
            factory.Close();
            TestHelper.CloseServiceModelObjects((System.ServiceModel.Channels.IChannel)channel, factory);
        }
        public void ErrorTelemetryEventsContainDetailedInfoOnTypedFault()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>()
                       .ShouldWaitForCompletion();

            using (host)
            {
                host.Open();
                ISimpleService client = host.GetChannel();
                try
                {
                    client.CallFailsWithTypedFault();
                }
                catch
                {
                }
            }

            var error = (from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item).Cast <ExceptionTelemetry>().First();

            Assert.IsNotNull(error.Exception);
            Assert.IsNotNull(error.Context.Operation.Id);
            Assert.IsNotNull(error.Context.Operation.Name);
        }
        public void ErrorTelemetryEventsAreGeneratedOnExceptionAndIEDIF_True()
        {
            TestTelemetryChannel.Clear();
            var host = new HostingContext <SimpleService, ISimpleService>()
                       .ShouldWaitForCompletion()
                       .IncludeDetailsInFaults();

            using (host)
            {
                host.Open();

                ISimpleService client = host.GetChannel();
                try
                {
                    client.CallFailsWithException();
                }
                catch
                {
                }
            }

            var errors = from item in TestTelemetryChannel.CollectedData()
                         where item is ExceptionTelemetry
                         select item;

            Assert.IsTrue(errors.Count() > 0);
        }
        public void WrongPassedIdentityTest()
        {
            ISimpleService service = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            SimpleContext.Get().Username = null;
            service.TestPassedIdentity().Should().Be.False();
        }
예제 #15
0
        public void Test_AddService()
        {
            ObjectBuilder.Add <ISimpleService, SimpleService>();
            ISimpleService simpleService = ObjectBuilder.Get <ISimpleService>();

            Assert.IsNotNull(simpleService);
            Assert.AreEqual(typeof(SimpleService), simpleService.GetType());
        }
예제 #16
0
 public ComplexService(ISimpleService simple)
 {
     if (simple == null)
     {
         throw new ArgumentNullException(nameof(simple));
     }
     _simple = simple;
 }
예제 #17
0
        private static void TestProxy()
        {
            ISimpleService svc = TransparentProxy.Create(new ProxyService());

            svc.Execute();
            var rst = svc.GetResult();

            Console.WriteLine("执行结果为:" + rst);
        }
예제 #18
0
        public MainWindow(ISimpleService simpleService)
        {
            InitializeComponent();

            _simpleService = simpleService;

            _worker.DoWork += _worker_DoWork;
            _worker.RunWorkerAsync();
        }
예제 #19
0
        public LookupController(ISimpleService lookupService)
        {
            if (lookupService == null)
            {
                throw new ArgumentNullException("lookupService");
            }

            _lookupService = lookupService;
        }
예제 #20
0
        private static void TestAopDecorator()
        {
            ISimpleService svc = Proxy.Of <OtherService, ISimpleService>(1);

            svc.Execute();
            var rst = svc.GetResult();

            Console.WriteLine("执行结果为:" + rst);
            Proxy.Save();
        }
예제 #21
0
        private static void TestAopWrapper()
        {
            ISimpleService svc = AOPFactory.CreateInstance <OtherService, ISimpleService>(1);

            svc.Execute();
            var rst = svc.GetResult();

            Console.WriteLine("执行结果为:" + rst);
            AOPFactory.Save();
        }
        public void TestSelfType()
        {
            SelfType type = new SelfType();

            type.SelfProperty = type;

            ISimpleService svc = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            svc.TestSelfType(type).Should().Be.True();
        }
        public void HeaderPassingTest()
        {
            ISimpleService service = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            SimpleContext.Get().ExtendedInfo["returnMe"] = "123";
            service.TestHeaderPassing().Should().Be("123");

            SimpleContext.Get().ExtendedInfo["returnMe"] = "1234";
            service.TestHeaderPassing().Should().Be("1234");
        }
        public void StackReferenceExpressionSerializationTest()
        {
            ISimpleService service             = Simply.Do[ConfigKey].Resolve <ISimpleService>();
            int            hh                  = 42;
            Expression <Predicate <int> > pred = i => i == hh;
            EditableExpression            expr = EditableExpression.Create(Funcletizer.PartialEval(pred));

            service.TestExpression(expr, 41).Should().Be.False();
            service.TestExpression(expr, 42).Should().Be.True();
        }
예제 #25
0
 public HomeViewModel(IMvxNavigationService navigationService,
                      IMvxLogProvider logProvider,
                      ISimpleService simpleService,
                      IStationRepository stationService)
 {
     _navigationService = navigationService;
     _log            = logProvider.GetLogFor <HomeViewModel>();
     _simpleService  = simpleService;
     _stationService = stationService;
 }
        public void IsClientSideContextReturnsFalseForServerChannel()
        {
            using (var host = new HostingContext <SimpleService, ISimpleService>())
            {
                host.Open();
                ISimpleService client = host.GetChannel();

                Assert.IsFalse(client.CallIsClientSideContext());
            }
        }
예제 #27
0
        public void IsSingletonShouldBeFalseWhenInstanceContextModeIsPerSession()
        {
            System.ServiceModel.ChannelFactory <ISimpleService> factory = DispatcherHelper.CreateChannelFactory <PerSessionSimpleService, ISimpleService>();
            factory.Open();
            ISimpleService channel = factory.CreateChannel();

            channel.Echo(input);

            factory.Close();
        }
 public void TelemetryEventsAreGeneratedOnServiceCall()
 {
     TestTelemetryChannel.Clear();
     using (var host = new HostingContext <SimpleService, ISimpleService>())
     {
         host.Open();
         ISimpleService client = host.GetChannel();
         client.GetSimpleData();
         Assert.IsTrue(TestTelemetryChannel.CollectedData().Count > 0);
     }
 }
예제 #29
0
        static void Run(string endpointConfigurationName)
        {
            Console.WriteLine("Press enter to invoke PrintMessage operation on the service with " + endpointConfigurationName + " endpoint configuration");
            Console.ReadLine();

            var            factory = new ChannelFactory <ISimpleService>(endpointConfigurationName);
            ISimpleService proxy   = factory.CreateChannel();

            proxy.PrintMessage("Calling form Console Client.");

            ((ICommunicationObject)proxy).Close();
        }
        public void SimpleExpressionSerializationTest()
        {
            using (Simply.KeyContext(ConfigKey))
            {
                ISimpleService service             = Simply.Do.Resolve <ISimpleService>();
                Expression <Predicate <int> > pred = i => i == 42;
                EditableExpression            expr = EditableExpression.Create(Funcletizer.PartialEval(pred));

                service.TestExpression(expr, 41).Should().Be.False();
                service.TestExpression(expr, 42).Should().Be.True();
            }
        }
        public void HeaderPassingAndReturningTest()
        {
            ISimpleService service = Simply.Do[ConfigKey].Resolve <ISimpleService>();

            SimpleContext.Get().ExtendedInfo["returnMe"] = 12345;
            service.TestHeaderPassingAndReturning().Should().Be(12345);
            SimpleContext.Get().ExtendedInfo["returnMe"].Should().Be(12347);

            SimpleContext.Get().ExtendedInfo["returnMe"] = 666;
            service.TestHeaderPassingAndReturning().Should().Be(666);
            SimpleContext.Get().ExtendedInfo["returnMe"].Should().Be(668);
        }
        public SimpleService(ISimpleService service)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
            ServiceID = "urn:uuid:6fa33842-ab2e-4eeb-b241-4f735013c4ec";
            ServiceTypeName = "SimpleService";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWayRequest"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TypeCheckRequest"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "AnyCheckRequest"));

            // Add event sources here
        }
        public SimpleService(ISimpleService service, ProtocolVersion version) : 
                base(version)
        {
            // Set the service implementation properties
            m_service = service;

            // Set base service properties
            ServiceNamespace = new WsXmlNamespace("sim", "http://schemas.example.org/SimpleService");
            ServiceID = "urn:uuid:5b0dd589-9f8c-4c23-b797-01ca3092b1ed";
            ServiceTypeName = "SimpleService";

            // Add service types here
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "OneWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TwoWay"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "TypeCheck"));
            ServiceOperations.Add(new WsServiceOperation("http://schemas.example.org/SimpleService", "AnyCheck"));

            // Add event sources here
        }
예제 #34
0
        public RegisterController(IUserService userService, ILoginService loginService, ISimpleService lookupService)
        {
            if (userService == null)
            {
                throw new ArgumentNullException("userService");
            }

            if (loginService == null)
            {
                throw new ArgumentNullException("loginService");
            }

            if (lookupService == null)
            {
                throw new ArgumentNullException("lookupService");
            }

            _lookupService = lookupService;
            _loginService = loginService;
            _userService = userService;
        }
예제 #35
0
 public ComplexWorker(ISimpleService service)
 {
     NestedSimpleService = service;
 }
 public SimpleServiceWithOneSimpleDependency(ISimpleService simpleService)
 {
     _simpleService = simpleService;
 }
		public SealedComponentWithDependency(ISimpleService dependency)
		{
			Dependency = dependency;
		}
예제 #38
0
		public DependsOnThrowingComponent(ISimpleService service, ThrowsInCtor throws)
		{
		}
 public SimpleService(ISimpleService service) : 
         this(service, new ProtocolVersion10())
 {
 }
예제 #40
0
 public CompositeServiceImpl(ISimpleService simpleService)
 {
     SimpleService = simpleService;
 }
예제 #41
0
		public HasCtorDependency(ISimpleService dependency)
		{
			Dependency = dependency;
		}
		public ThrowsInCtorWithDisposableDependency(ISimpleService depedency)
		{
			throw new Exception("Booooo!");
		}
예제 #43
0
 public void SetDummy(MarshalByRefObject obj)
 {
     _service = (ISimpleService)obj;
 }
		public TrivialComponentWithDependency(ISimpleService dependency)
		{
			Dependency = dependency;
		}