public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) { foreach (ChannelDispatcher channelDispatcher in serviceHostBase.ChannelDispatchers) { channelDispatcher.ErrorHandlers.Add(new StandardServiceErrorHandler(m_BizExceptionTypeList, m_ExceptionHandler)); } }
public void AddBindingParameters(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection <ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) { //Logger.WriteLogEntry("Inside the AddBindingParameters"); }
/// <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) { }
/// <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(); }
/// <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); } } } } }
/// <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; }
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."); } } } }
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(); }
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()); } } }
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"); } } }
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()); } } }
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); } } }
/// <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; }
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()); } } }
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)); } } }
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); } } }
/// <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()); } } } }
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); } } } }
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); }
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); } } } }
/// <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>()); } } } }
/// <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); } } } }
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); } } } }
/// <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"); } }