¿Por qué el descubrimiento de WCF no funciona con el host de fábrica de servicio personalizado en WCF?

I have created a custom ServiceHostFactory, a ServiceHost, a ServiceBehavior and a ServiceInstanceProvider for DI using unity in my IIS hosted WCF service.

After this UDP discovery has stopped working. How is the ServiceDiscovery behavior created by WCF? Where is the UDPDiscoveryEndpoint created? Am I overriding some behavior in the code below?

public class ServiceHostFactory : System.ServiceModel.Activation.ServiceHostFactory
{
    protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {   
        return new ServiceHost(serviceType, baseAddresses);
    }
}

public class ServiceHost : System.ServiceModel.ServiceHost
{ ....
    protected override void OnOpen(TimeSpan timeout)
    {
        Description.Behaviors.Add(new ServiceBehavior());            
        base.OnOpen(timeout);
    }
}

public class ServiceBehavior : IServiceBehavior
{
    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
        foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
        {
            var cd = cdb as ChannelDispatcher;
            if (cd != null)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {   
                    ed.DispatchRuntime.InstanceProvider = new ServiceInstanceProvider(serviceDescription.ServiceType);
                }
            }
        }
    }
}

public class ServiceInstanceProvider : IInstanceProvider
{...
    public object GetInstance(InstanceContext instanceContext, Message message)
    {
        return Container.Instance.Resolve(_serviceType);
    }
}

preguntado el 12 de junio de 12 a las 12:06

Why did you call your own class the same name as the existing base class? (ServiceHostFactory y ServiceHost) This is garantiza to lead to confusion and things going wrong ... if you descend from a class - use a different class name to avoid confusion... -

Hi Marc, I have used different names in the actual code ofcourse. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.