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(); } } }
private void Variation_TwoAttributesDifferentTypes() { ChannelFactory <IContractBehaviorBasic_TwoAttributesDifferentTypes> cf = GetChannelFactory <IContractBehaviorBasic_TwoAttributesDifferentTypes>(); try { cf.Open(); string expected = "IContractBehavior:ClientContract.CustomContractBehaviorAttribute;IContractBehavior:ClientContract.OtherCustomContractBehaviorAttribute;"; Assert.Equal(expected, BehaviorInvokedVerifier.ValidateClientInvokedBehavior(cf.Endpoint)); IContractBehaviorBasic_TwoAttributesDifferentTypes clientProxy = cf.CreateChannel(); string HelloStr = "TwoAttributesDifferentTypes"; string returnStr = clientProxy.StringMethod(HelloStr); Assert.Equal(HelloStr, returnStr); } catch { throw; } finally { if (cf != null && cf.State == System.ServiceModel.CommunicationState.Opened) { cf.Close(); } } }
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(); } } }
private void Variation_MisplacedAttributes() { ChannelFactory <IContractBehaviorBasic_MisplacedAttributes> cf = GetChannelFactory <IContractBehaviorBasic_MisplacedAttributes>(); try { IContractBehaviorBasic_MisplacedAttributes clientProxy = cf.CreateChannel(); Assert.True(string.IsNullOrEmpty(BehaviorInvokedVerifier.ValidateClientInvokedBehavior(cf.Endpoint))); string HelloStr = "MisplacedAttributes"; string returnStr = clientProxy.StringMethod(HelloStr); Assert.Equal(HelloStr, returnStr); } catch { throw; } finally { if (cf != null && cf.State == System.ServiceModel.CommunicationState.Opened) { cf.Close(); } } }
public string ServiceContractMethod(string s) { BehaviorInvokedVerifier.ValidateServiceInvokedBehaviors(OperationContext.Current.Host.Description, s); return(s); }