コード例 #1
0
        private void AddBehaviors(string behaviorConfiguration, ServiceEndpoint serviceEndpoint, ServiceModelSectionGroup group)
        {
            if (string.IsNullOrEmpty(behaviorConfiguration))
            {
                return;
            }
            if (group == null)
            {
                return;
            }
            EndpointBehaviorElement endpointBehaviorElement = group.Behaviors.EndpointBehaviors[behaviorConfiguration];

            if (endpointBehaviorElement != null)
            {
                for (int i = 0; i < endpointBehaviorElement.Count; i++)
                {
                    BehaviorExtensionElement behaviorExtensionElement = endpointBehaviorElement[i];
                    object obj = behaviorExtensionElement.GetType().InvokeMember("CreateBehavior", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, behaviorExtensionElement, null);
                    if (obj != null)
                    {
                        serviceEndpoint.Behaviors.Add((IEndpointBehavior)obj);
                    }
                }
            }
        }
コード例 #2
0
ファイル: WCFConfigProvider.cs プロジェクト: ITanyx/GitTest
        private static T CreateBehavior <T>(BehaviorExtensionElement behaviorElement)
        {
            MethodInfo method = behaviorElement.GetType().GetMethod("CreateBehavior", BindingFlags.Instance | BindingFlags.NonPublic);

            if (method != null)
            {
                return((T)method.Invoke(behaviorElement, null));
            }
            return(default(T));
        }
コード例 #3
0
        public static IEndpointBehavior CreateBehavior(BehaviorExtensionElement behaviorExtension)
        {
            IEndpointBehavior endPointBehavior = (IEndpointBehavior)behaviorExtension.GetType().InvokeMember(
                "CreateBehavior",
                BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
                null,
                behaviorExtension,
                null);

            return(endPointBehavior);
        }
コード例 #4
0
        /// <summary>
        /// Method ApplyMultiBehaviors
        /// </summary>
        /// <param name="serviceModelSectionGroup">ServiceModel section group.</param>
        /// <returns>true if succeeded; otherwise, false.</returns>
        private bool ApplyMultiBehaviors(ServiceModelSectionGroup serviceModelSectionGroup)
        {
            if (serviceModelSectionGroup == null)
            {
                return(false);
            }

            foreach (ServiceBehaviorElement element in serviceModelSectionGroup.Behaviors.ServiceBehaviors)
            {
                foreach (BehaviorExtensionElement behavior in element)
                {
                    BehaviorExtensionElement behaviorExtensionElement = behavior;

                    object extention = behaviorExtensionElement.GetType().InvokeMember(
                        "CreateBehavior",
                        BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
                        null,
                        behaviorExtensionElement,
                        null);

                    if (extention == null)
                    {
                        continue;
                    }

                    IServiceBehavior serviceBehavior = (IServiceBehavior)extention;

                    bool isBehaviorExist = false;

                    foreach (IServiceBehavior item in this.Description.Behaviors)
                    {
                        if (item.GetType().Name == serviceBehavior.GetType().Name)
                        {
                            isBehaviorExist = true;

                            break;
                        }
                    }

                    if (isBehaviorExist)
                    {
                        break;
                    }

                    this.Description.Behaviors.Add((IServiceBehavior)extention);
                }
            }

            return(true);
        }
コード例 #5
0
 public static object CreateBehavior(this BehaviorExtensionElement extensionElement)
 {
     try
     {
         return(extensionElement.GetType().
                GetMethod(
                    "CreateBehavior",
                    BindingFlags.Instance |
                    BindingFlags.NonPublic).
                Invoke(extensionElement, new object[] { }));
     }
     catch (TargetInvocationException ex)
     {
         throw ex.InnerException;
     }
 }
コード例 #6
0
 private void method_2(string string_1, ServiceEndpoint serviceEndpoint_0, ServiceModelSectionGroup serviceModelSectionGroup_0)
 {
     if (!string.IsNullOrEmpty(string_1))
     {
         EndpointBehaviorElement endpointBehaviorElement = serviceModelSectionGroup_0.Behaviors.EndpointBehaviors[string_1];
         for (int i = 0; i < endpointBehaviorElement.Count; i++)
         {
             BehaviorExtensionElement behaviorExtensionElement = endpointBehaviorElement[i];
             object obj = behaviorExtensionElement.GetType().InvokeMember("CreateBehavior", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, behaviorExtensionElement, null);
             if (obj != null)
             {
                 serviceEndpoint_0.Behaviors.Add((IEndpointBehavior)obj);
             }
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Adds the configured behavior to the selected endpoint
        /// </summary>
        /// <param name="behaviorConfiguration"></param>
        /// <param name="serviceEndpoint"></param>
        /// <param name="group"></param>
        private void AddBehaviors(string behaviorConfiguration, ServiceEndpoint serviceEndpoint, ServiceModelSectionGroup group)
        {
            EndpointBehaviorElement behaviorElement = group.Behaviors.EndpointBehaviors[behaviorConfiguration];

            for (int i = 0; i < behaviorElement.Count; i++)
            {
                BehaviorExtensionElement behaviorExtension = behaviorElement[i];
                object extension = behaviorExtension.GetType().InvokeMember("CreateBehavior",
                                                                            BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
                                                                            null, behaviorExtension, null);
                if (extension != null)
                {
                    serviceEndpoint.Behaviors.Add((IEndpointBehavior)extension);
                }
            }
        }
コード例 #8
0
        protected internal static void AddBehaviors(string behaviorConfiguration, ServiceEndpoint serviceEndpoint, BehaviorsSection section)
        {
            if (string.IsNullOrEmpty(behaviorConfiguration))
            {
                return;
            }
            EndpointBehaviorElement behaviorElement = section.EndpointBehaviors[behaviorConfiguration];

            for (int i = 0; i < behaviorElement.Count; i++)
            {
                BehaviorExtensionElement behaviorExtension = behaviorElement[i];
                object extension = behaviorExtension.GetType().InvokeMember("CreateBehavior", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, behaviorExtension, null);
                if (extension != null)
                {
                    serviceEndpoint.Behaviors.Add((IEndpointBehavior)extension);
                }
            }
        }