0

I am using DiscoveryEndpoints in WCF but I have noticed that when a service is being discovered and the DiscoveryEndpoint is contacted it will actually cause an instance of the service to be created. I do not want this.

This is almost certainly related to the fact I am using a custom instance provider (to support StructureMap) - which applies custom InstanceProvider to each EndpointDispatcher.

It seems I only want to apply the custom InstanceProvider for the endpoints whose contract actually match the service implementation.

Any ideas?

Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113

1 Answers1

1

I think I worked it out... I am just ignoring anything that has IsSystemEndpoint set:

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
        {
            ChannelDispatcher cd = cdb as ChannelDispatcher;
            if (cd != null)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {
                    if (!ed.IsSystemEndpoint) // Ignore MEX etc
                        ed.DispatchRuntime.InstanceProvider =
                            new StructureMapInstanceProvider(serviceDescription.ServiceType);
                }
            }
        }
    }
Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113