UnityServiceHost for injected wcf service not working in combination with discovery

Nov 19, 2010 at 12:34 PM

When I host my service with the UnityServiceHost class (http://initializecomponent.blogspot.com/2008/06/integrating-unity-with-wcf.html) the service is not discoverable.
If I change the hosting object back to ServiceHost and add a parameterless constructor discovery works just fine, however I need the injection here.

So what am I missing?


Nov 22, 2010 at 10:04 AM
Edited Nov 22, 2010 at 12:05 PM
You have to check wherther it is your own endpoint and not a system endpoint (like discovery, mex etc)
So here it is:
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
      foreach (ChannelDispatcherBase channelDispatcherBase in serviceHostBase.ChannelDispatchers)
      {
        ChannelDispatcher channelDispatcher = channelDispatcherBase as ChannelDispatcher;
        if (channelDispatcher != null)
        {
          foreach (EndpointDispatcher ed in channelDispatcher.Endpoints)
          {
            // Only apply Dispatch Behavior to custom endpoints
            if (!ed.IsSystemEndpoint)
            {
              this.InstanceProvider.ServiceType = serviceDescription.ServiceType;
              ed.DispatchRuntime.InstanceProvider = this.InstanceProvider;
            }
          }
        }
      }
    }