DevForce Help Reference
ServiceHostEvents Class
Members  Example 


Provides a means of customizing a ServiceHost.
Syntax
'Declaration
 
<DefaultExportAttribute(IsDefault=True, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.ServiceHostEvents)>
Public Class ServiceHostEvents 
'Usage
 
Dim instance As ServiceHostEvents
[DefaultExport(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.ServiceHostEvents)]
public class ServiceHostEvents 
Remarks
The WCF services comprising the BOS, the EntityService and all EntityServers, can be customized prior to use by sub-typing this class and overriding the methods provided.
Example
using System;
using System.ComponentModel.Composition;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using IdeaBlade.EntityModel.Server;

  public class MyServiceHostEvents : ServiceHostEvents {

    // Called after an endpoint is created.
     public override void OnEndpointCreated(ServiceEndpoint endpoint) {

       // Here we'll tweak the binding to add message security. 
       // Bindings used in DevForce are by default the CustomBinding type.
      if (endpoint.Binding is CustomBinding) {

        var binding = endpoint.Binding as CustomBinding;
        var elements = binding.CreateBindingElements();

        // This just inserts  the equivalent of a <security authenticationMode="SspiNegotiated">
        // element to the binding.
        var sec = new SymmetricSecurityBindingElement();
        sec.ProtectionTokenParameters = new System.ServiceModel.Security.Tokens.SspiSecurityTokenParameters();
        elements.Insert(1, sec);

        // Replace the binding on the endpoint.
        endpoint.Binding = new CustomBinding(elements);
      }

      // Let's change the default timeouts too.
      endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 2, 0);
      endpoint.Binding.SendTimeout = new TimeSpan(0, 2, 0);
    }

    // Called after the service has been configured but before it has opened.
    public override void OnServiceHostCreated(System.ServiceModel.ServiceHost host) {

      // Let's add a MEX endpoint and metadata behavior, using this utility function.
      IdeaBlade.EntityModel.RemoteServiceFns.AddMexEndpoint(host);

    }
  }
Inheritance Hierarchy

System.Object
   IdeaBlade.EntityModel.Server.ServiceHostEvents

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ServiceHostEvents Members
IdeaBlade.EntityModel.Server Namespace

Send Feedback