Пример #1
0
        public void WithIInputChannel_CanBuildChannelFactoryReturnsFalse()
        {
            TelemetryClient client  = new TelemetryClient();
            ClientContract  map     = new ClientContract(typeof(ISimpleService));
            var             element = new ClientTelemetryBindingElement(client, map);

            var            custom  = new CustomBinding(new NetMsmqBinding());
            BindingContext context = new BindingContext(custom, new BindingParameterCollection());

            Assert.IsFalse(element.CanBuildChannelFactory <IInputChannel>(context));
        }
        public void WhenClientIsNull_ConstructorThrowsException()
        {
            TelemetryClient client = null;
            ClientContract  map    = new ClientContract(typeof(ISimpleService));
            bool            failed = false;

            try
            {
                var element = new ClientTelemetryBindingElement(client, map);
            } catch (ArgumentNullException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "Constructor did not throw ArgumentNullException");
        }
        public void WhenContextIsNull_BuildChannelFactoryThrowsException()
        {
            TelemetryClient client = new TelemetryClient();
            ClientContract  map    = new ClientContract(typeof(ISimpleService));
            bool            failed = false;

            try
            {
                var element = new ClientTelemetryBindingElement(client, map);
                element.BuildChannelFactory <IRequestChannel>(null);
            } catch (ArgumentNullException)
            {
                failed = true;
            }
            Assert.IsTrue(failed, "BuildChannelFactory did not throw ArgumentNullException");
        }
Пример #4
0
        public void TestChannelShape <TChannel>(Binding binding, bool tryCreate = true)
        {
            TelemetryClient client  = new TelemetryClient();
            ClientContract  map     = new ClientContract(typeof(ISimpleService));
            var             element = new ClientTelemetryBindingElement(client, map);

            var            custom  = new CustomBinding(binding);
            BindingContext context = new BindingContext(custom, new BindingParameterCollection());

            Assert.IsTrue(element.CanBuildChannelFactory <TChannel>(context));

            if (tryCreate)
            {
                var factory = element.BuildChannelFactory <TChannel>(context);
                Assert.IsNotNull(factory, "BuildChannelFactory() returned null");
                factory.Close();
            }
        }
Пример #5
0
        void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            var contract = endpoint.Contract.ContractType;

            WcfClientEventSource.Log.ClientTelemetryApplied(contract.FullName);

            // in most cases, we'll create the description only once
            // since channel factories are cached by default in ClientBase<T>.
            // We could possibly cache this to avoid the hit in other scenarios.
            var description = new ClientContract(endpoint.Contract);
            var element     = new ClientTelemetryBindingElement(this.telemetryClient, description)
            {
                RootOperationIdHeaderName       = this.RootOperationIdHeaderName,
                ParentOperationIdHeaderName     = this.ParentOperationIdHeaderName,
                SoapRootOperationIdHeaderName   = this.SoapRootOperationIdHeaderName,
                SoapParentOperationIdHeaderName = this.SoapParentOperationIdHeaderName,
                SoapHeaderNamespace             = this.SoapHeaderNamespace
            };
            var collection = endpoint.Binding.CreateBindingElements();

            collection.Insert(0, element);
            endpoint.Binding = new CustomBinding(collection);
        }