Beispiel #1
0
        private void Variation_ByHandImplementsOther()
        {
            ChannelFactory <IContractBehaviorBasic_ByHand> cf = GetChannelFactory <IContractBehaviorBasic_ByHand>();

            try
            {
                var theBehavior = new MyMultiFacetedBehaviorAttribute();
                cf.Endpoint.Contract.ContractBehaviors.Add(theBehavior);
                cf.Open();
                string expected = "IContractBehavior:ClientContract.MyMultiFacetedBehaviorAttribute;";
                Assert.Equal(expected, BehaviorInvokedVerifier.ValidateClientInvokedBehavior(cf.Endpoint));
                IContractBehaviorBasic_ByHand clientProxy = cf.CreateChannel();
                string HelloStr  = "ByHandImplementsOther";
                string returnStr = clientProxy.StringMethod(HelloStr);
                Assert.Equal(HelloStr, returnStr);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (cf != null && cf.State == System.ServiceModel.CommunicationState.Opened)
                {
                    cf.Close();
                }
            }
        }
Beispiel #2
0
        private void Variation_ByHand(bool useHiddenProperty)
        {
            ChannelFactory <IContractBehaviorBasic_ByHand> cf = GetChannelFactory <IContractBehaviorBasic_ByHand>();

            try
            {
                string HelloStr = "ByHand";
                CustomContractBehaviorAttribute cb = new CustomContractBehaviorAttribute();
                if (useHiddenProperty)
                {
#if NET472
                    cf.Endpoint.Contract.Behaviors.Add(cb);
                    HelloStr = "ByHand_UsingHiddenProperty";
#endif
                }
                else
                {
                    cf.Endpoint.Contract.ContractBehaviors.Add(cb);
                }

                cf.Open();
                string expected = "IContractBehavior:ClientContract.CustomContractBehaviorAttribute;";
                Assert.Equal(expected, BehaviorInvokedVerifier.ValidateClientInvokedBehavior(cf.Endpoint));
                IContractBehaviorBasic_ByHand clientProxy = cf.CreateChannel();
                string returnStr = clientProxy.StringMethod(HelloStr);
                Assert.Equal(HelloStr, returnStr);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (cf != null && cf.State == System.ServiceModel.CommunicationState.Opened)
                {
                    cf.Close();
                }
            }
        }