public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
     {
         channelDispatcher.ErrorHandlers.Add(new StandardServiceErrorHandler(m_BizExceptionTypeList, m_ExceptionHandler));
     }
 }
Exemplo n.º 2
0
 public void AddBindingParameters(ServiceDescription serviceDescription,
                                  System.ServiceModel.ServiceHostBase serviceHostBase,
                                  System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints,
                                  BindingParameterCollection bindingParameters)
 {
     //Logger.WriteLogEntry("Inside the AddBindingParameters");
 }
Exemplo n.º 3
0
 /// <summary>
 /// Add the binding parameters.
 /// </summary>
 /// <param name="serviceDescription">The current service description.</param>
 /// <param name="serviceHostBase">The service host base.</param>
 /// <param name="endpoints">The current end point collection.</param>
 /// <param name="bindingParameters">The parameters.</param>
 void IServiceBehavior.AddBindingParameters(
     ServiceDescription serviceDescription,
     System.ServiceModel.ServiceHostBase serviceHostBase,
     System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints,
     System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Sets the credentials to use for the service host.
        /// </summary>
        /// <param name="serviceHost"></param>
        public void SetServiceCredentials(System.ServiceModel.ServiceHostBase serviceHost)
        {
            if (serviceHost == null)
            {
                throw new ArgumentNullException("serviceHost");
            }

            if (serviceHost.Credentials == null)
            {
                throw new ArgumentException("ServiceHost credentials may not be null.");
            }

            serviceHost.Credentials.ServiceCertificate.Certificate = null;

            // Set service certificate
            if (_enableSsl)
            {
                serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My,
                                                                          X509FindType.FindBySubjectName, Transport.ServiceDomainName);
            }

            // Set the trust level for client certificates
            X509ClientCertificateAuthentication x509ClientCertificateAuthentication =
                serviceHost.Credentials.ClientCertificate.Authentication;

            x509ClientCertificateAuthentication.CertificateValidationMode =
                X509CertificateValidationMode.PeerOrChainTrust;
            x509ClientCertificateAuthentication.TrustedStoreLocation       = StoreLocation.LocalMachine;
            x509ClientCertificateAuthentication.RevocationMode             = X509RevocationMode.NoCheck;
            x509ClientCertificateAuthentication.CustomCertificateValidator = new X509CertificateValidator();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Apply the dispatch error behavior.
        /// </summary>
        /// <param name="serviceDescription">The current service description.</param>
        /// <param name="serviceHostBase">The service host base.</param>
        void IServiceBehavior.ApplyDispatchBehavior(
            ServiceDescription serviceDescription,
            System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            IErrorHandler errorHandler;

            try
            {
                // Create a new instance of the error handler.
                errorHandler = (IErrorHandler)Activator.CreateInstance(
                    _errorHandlerType, new object[] { (String.IsNullOrEmpty(_configurationName) ? "" : _configurationName) });
            }
            catch (MissingMethodException e)
            {
                throw new ArgumentException("The errorHandlerType specified in the " +
                                            "ErrorBehaviorAttribute constructor must have a public empty constructor.", e);
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException("The errorHandlerType specified in the " +
                                            "ErrorBehaviorAttribute constructor must implement " +
                                            "System.ServiceModel.Dispatcher.IErrorHandler.", e);
            }

            // For each channel add the error handler types.
            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
                channelDispatcher.ErrorHandlers.Add(errorHandler);
            }
        }
        /// <summary>
        /// Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.
        /// </summary>
        /// <param name="serviceDescription">The service description.</param>
        /// <param name="serviceHostBase">The host that is currently being built.</param>
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            //foreach (var cdb in serviceHostBase.ChannelDispatchers)
            //{
            //    var cd = cdb as ChannelDispatcher;

            //    if (cd != null)
            //    {
            //        foreach (var ed in cd.Endpoints)
            //        {
            //            ed.DispatchRuntime.InstanceProvider = new DependencyInjectionInstanceProvider(serviceDescription.ServiceType);
            //        }
            //    }
            //}

            foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
            {
                foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                {
                    if (endpointDispatcher.ContractName != "IMetadataExchange")
                    {
                        string contractName = endpointDispatcher.ContractName;

                        ServiceEndpoint serviceEndpoint = serviceDescription.Endpoints.FirstOrDefault(e => e.Contract.Name == contractName);

                        if (serviceEndpoint != null)
                        {
                            endpointDispatcher.DispatchRuntime.InstanceProvider = new DependencyInjectionInstanceProvider(_container, serviceEndpoint.Contract.ContractType);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Provides the ability to pass custom data to binding elements
 /// to support the contract implementation.
 /// </summary>
 /// <param name="serviceDescription">The service description of the service.</param>
 /// <param name="serviceHostBase">The host of the service.</param>
 /// <param name="endpoints">The service endpoints.</param>
 /// <param name="bindingParameters">Custom objects to which binding elements have access.
 /// </param>
 public void AddBindingParameters(ServiceDescription serviceDescription,
                                  System.ServiceModel.ServiceHostBase serviceHostBase,
                                  System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints,
                                  System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
     return;
 }
Exemplo n.º 8
0
        public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            Type            serviceType = serviceDescription.ServiceType;
            ConstructorInfo ctor        = serviceType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);

            if (ctor == null)
            {
                throw new InvalidOperationException("Service must have a parameterless, public constructor.");
            }

            MethodInfo[] methods = serviceType.GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(m => m.DeclaringType == serviceType).ToArray();
            if (methods.Length == 0)
            {
                throw new InvalidOperationException("Service does not have any public methods.");
            }

            foreach (MethodInfo method in methods)
            {
                foreach (ParameterInfo parameter in method.GetParameters())
                {
                    if (parameter.ParameterType.IsByRef)
                    {
                        throw new InvalidOperationException("This behavior does not support public methods with out/ref parameters.");
                    }
                }
            }
        }
Exemplo n.º 9
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            //

            foreach (var endpoint in serviceDescription.Endpoints)
            {
                endpoint.Contract.Behaviors.Add(new DispatchByBodyElementBehaviorAttribute());
            }
        }
 public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
 {
     //提供方法执行的上下文环境
     //OperationContext context = OperationContext.Current;
     //获取传进的消息属性
     //MessageProperties properties = context.IncomingMessageProperties;
     ///获取消息发送的远程终结点IP和端口
     //RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
     //throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher chDisp in serviceHostBase.ChannelDispatchers)
     {
         foreach (EndpointDispatcher epDisp in chDisp.Endpoints)
         {
             epDisp.DispatchRuntime.MessageInspectors.Add(new BearerTokenMessageInspector());
         }
     }
 }
Exemplo n.º 12
0
 public void Validate(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ServiceEndpoint se in serviceDescription.Endpoints)
     {
         if (se.Binding.Name.Equals("BasicHttpBinding"))
         {
             throw new FaultException("Please don't use the BasicHttpBinding...choose a secure endpoint binding");
         }
     }
 }
Exemplo n.º 13
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
     {
         foreach (var endpoint in dispatcher.Endpoints)
         {
             endpoint.DispatchRuntime.MessageInspectors.Add(new WcfDebugPrint());
         }
     }
 }
Exemplo n.º 14
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher cd in serviceHostBase.ChannelDispatchers)
     {
         foreach (EndpointDispatcher ed in cd.Endpoints)
         {
             ed.DispatchRuntime.MessageInspectors.Add(this);
         }
     }
 }
Exemplo n.º 15
0
 /// <summary>
 /// Provides the ability to change run-time property values or
 /// insert custom extension objects such as error handlers,
 /// message or parameter interceptors,
 /// security extensions, and other custom extension objects.
 /// </summary>
 /// <param name="serviceDescription">The service description.</param>
 /// <param name="serviceHostBase">The host that is currently being built.</param>
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
                                   System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
     {
         dispatcher.Endpoints
         .ToList()
         .ForEach(x => x.DispatchRuntime.MessageInspectors.Add(new WCFInterceptor()));
     }
     //this.serviceHost = serviceHostBase;
 }
Exemplo n.º 16
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher channelDispather in serviceHostBase.ChannelDispatchers)
     {
         foreach (var endpoint in channelDispather.Endpoints)
         {
             // holyshit DispatchRuntime
             endpoint.DispatchRuntime.MessageInspectors.Add(new CrossDomainInspector());
         }
     }
 }
Exemplo n.º 17
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcherBase dispatcherBase in
              serviceHostBase.ChannelDispatchers)
     {
         var channelDispatcher = dispatcherBase as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             channelDispatcher.ErrorHandlers.Add(new HostErrorHandler(_info));
         }
     }
 }
Exemplo n.º 18
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            var handler = (IErrorHandler)Activator.CreateInstance(_errorHandlerType);

            foreach (ChannelDispatcherBase dispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                var channelDispatcher = dispatcherBase as ChannelDispatcher;
                if (channelDispatcher != null)
                {
                    channelDispatcher.ErrorHandlers.Add(handler);
                }
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// 3. olarak çağırılır.
 /// </summary>
 /// <param name="serviceDescription"></param>
 /// <param name="serviceHostBase"></param>
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher chDispatcher in serviceHostBase.ChannelDispatchers)
     {
         foreach (EndpointDispatcher epDispatcher in chDispatcher.Endpoints)
         {
             epDispatcher.DispatchRuntime.MessageInspectors.Add(this);
             foreach (DispatchOperation op in epDispatcher.DispatchRuntime.Operations)
             {
                 op.ParameterInspectors.Add(new ParameterInspector());
             }
         }
     }
 }
Exemplo n.º 20
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     for (Int32 i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
     {
         ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
             {
                 SecurityMessageInspector inspector = new SecurityMessageInspector();
                 endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
             }
         }
     }
 }
Exemplo n.º 21
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            Type serviceType = serviceDescription.ServiceType;
            ContractDescription contractDescription = CreateContractDescription(serviceType);
            string endpointAddress = serviceHostBase.BaseAddresses[0].AbsoluteUri;

            ServiceEndpoint endpoint = new ServiceEndpoint(contractDescription, createBinding(), new EndpointAddress(new Uri(endpointAddress)));

            serviceDescription.Endpoints.Add(endpoint);

            ChannelDispatcher dispatcher = CreateChannelDispatcher(endpoint, serviceType);

            serviceHostBase.ChannelDispatchers.Add(dispatcher);

            //AssociateEndpointToDispatcher(endpoint, dispatcher);
        }
Exemplo n.º 22
0
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
                                   System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     //Logger.WriteLogEntry("Inside Apply Dispatch Behavior");
     for (int i = 0; i < serviceHostBase.ChannelDispatchers.Count; i++)
     {
         ChannelDispatcher channelDispatcher = serviceHostBase.ChannelDispatchers[i] as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
             {
                 MessageInspector inspector = new MessageInspector();
                 endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
             }
         }
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Sets the behavior for the given servicehost.
        /// </summary>
        /// <param name="serviceHost"></param>
        public void SetBehavior(System.ServiceModel.ServiceHostBase serviceHost)
        {
            if (serviceHost == null)
            {
                throw new ArgumentNullException("serviceHost");
            }

            SetServiceCredentials(serviceHost);
            ServiceDescription serviceDescription = serviceHost.Description;

            EnableDebugging(serviceDescription);
            OptimizeServiceThrottling(serviceDescription);
            ReplaceDataContractSerializer(serviceDescription);

            // Add mex as the last thing
            AddMetadataEndpoint(serviceHost);
        }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
     {
         ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
         if (channelDispatcher != null)
         {
             foreach (EndpointDispatcher endpoint in channelDispatcher.Endpoints)
             {
                 // set the intance that will create service instances
                 endpoint.DispatchRuntime.InstanceProvider = this;
                 // attach a message inspector to manage the nhibernate session binding to the session context
                 endpoint.DispatchRuntime.MessageInspectors.Add((IDispatchMessageInspector)container.Resolve <IDispatchMessageInspector>());
             }
         }
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Closes a service host
        /// </summary>
        /// <param name="serviceHost"></param>
        public static void CloseServiceHost(System.ServiceModel.ServiceHostBase serviceHost)
        {
            if (serviceHost == null || !IsServiceHostOpen(serviceHost))
            {
                return;
            }

            try
            {
                serviceHost.Close();
            }
            catch (Exception)
            {
                {
                }
            }
        }
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
                                          System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            object behavior;

            try
            {
                behavior = Activator.CreateInstance(_behaviorType);
            }
            catch (MissingMethodException e)
            {
                throw new ArgumentException(e.Message);
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException(e.Message);
            }
            foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
            {
                if (behavior is IParameterInspector)
                {
                    foreach (EndpointDispatcher epDisp in channelDispatcher.Endpoints)
                    {
                        foreach (DispatchOperation op in epDisp.DispatchRuntime.Operations)
                        {
                            op.ParameterInspectors.Add((IParameterInspector)behavior);
                        }
                    }
                }
                else if (behavior is IErrorHandler)
                {
                    channelDispatcher.ErrorHandlers.Add((IErrorHandler)behavior);
                }
                else if (behavior is IDispatchMessageInspector)
                {
                    foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                    {
                        endpointDispatcher.DispatchRuntime.MessageInspectors.Add((IDispatchMessageInspector)behavior);
                    }
                }
            }
        }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     //Go over all endpoints of this service
     foreach (var endpoint in serviceHostBase.Description.Endpoints)
     {
         //for each operation (eg. method)
         foreach (var operation in endpoint.Contract.Operations)
         {
             //if an Invoker is already preset, merge Checklists, otherwise, create new
             if (operation.Behaviors.Contains(typeof(CustomSecurityCheckAttribute)))
             {
                 var customsecuritychecksbehavior = operation.Behaviors[typeof(CustomSecurityCheckAttribute)] as CustomSecurityCheckAttribute;
                 customsecuritychecksbehavior.CheckList.AddRange(this.CheckList);
             }
             else
             {
                 operation.Behaviors.Add(new CustomSecurityCheckAttribute(CheckList));
             }
         }
     }
 }
 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
 {
     foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers)
     {
         if (channelDispatcher == null)
         {
             continue;
         }
         foreach (var endPoint in channelDispatcher.Endpoints)
         {
             if (endPoint == null)
             {
                 continue;
             }
             foreach (var opertaion in endPoint.DispatchRuntime.Operations)
             {
                 opertaion.ParameterInspectors.Add(this);
             }
         }
     }
 }
Exemplo n.º 29
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
        {
            foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;

                if (channelDispatcher != null)
                {
                    foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints)
                    {
                        Type interfaceType = serviceDescription.ServiceType.GetInterfaces()[0];

                        if (interfaceType == null)
                        {
                            throw new InvalidOperationException(string.Format("Tipo: {0}", serviceDescription.ServiceType.Name));
                        }

                        endpointDispatcher.DispatchRuntime.InstanceProvider = new WcfServiceHostInstanceProvider(interfaceType);
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Adds a mex endpoint to a service host.
        /// </summary>
        /// <param name="serviceHost"></param>
        public void AddMetadataEndpoint(System.ServiceModel.ServiceHostBase serviceHost)
        {
            if (serviceHost == null)
            {
                throw new ArgumentNullException("serviceHost");
            }

            if (serviceHost.GetType() == typeof(DataServiceHost) ||
                TypeHelper.IsSubclassOf(serviceHost.GetType(), typeof(DataServiceHost)))
            {
                return;
            }

            System.ServiceModel.Channels.Binding binding = null;

            if (_protocol == Protocol.Http && !_enableSsl)
            {
                binding = Binding.GetMexHttpBinding();
            }
            else if (_protocol == Protocol.Http && _enableSsl)
            {
                binding = Binding.GetMexHttpsBinding();
            }
            else if (_protocol == Protocol.Tcp)
            {
                //binding = Binding.GetMexNetTcpBinding();
            }
            else
            {
                throw new ServiceException("Could not determine metadata binding for servicehost.");
            }

            if (binding != null)
            {
                serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, binding, "mex");
            }
        }