IdeaBlade DevForce 2010 Help Reference
ServiceHostEvents Class
Members  Example  See Also  Send Feedback
IdeaBlade.EntityModel.Server Assembly > IdeaBlade.EntityModel.Server Namespace : ServiceHostEvents Class



Provides a means of customizing a ServiceHost.

Syntax

Visual Basic (Declaration) 
<DefaultExportAttribute(IsDefault=True, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.ServiceHostEvents)>
Public Class ServiceHostEvents 
Visual Basic (Usage)Copy Code
Dim instance As ServiceHostEvents
C# 
[DefaultExportAttribute(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.ServiceHostEvents)]
public class ServiceHostEvents 
C++/CLI 
[DefaultExportAttribute(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.Server.ServiceHostEvents)]
public ref class ServiceHostEvents 

Example

C#Copy Code
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);

    }
  }

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.

Inheritance Hierarchy

System.Object
   IdeaBlade.EntityModel.Server.ServiceHostEvents

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.