How to add endpoint behavior to open an IIS-enabled WCF service

I have a WCF service with IIS support and I need to add endpoint behavior to it. I cannot just add it to web.config. (We need to support the plugin architecture, and the plugins will not have access to my web.config.) I tried to put this in a static constructor for the service:

var endpointDispatcher = OperationContext.Current.EndpointDispatcher;
SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector();
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);

but he throws an exception: "This value cannot be changed after opening ServiceHost." If I call host.Close () before adding the inspector object, it still throws the same exception.

I tried this too:

var host = OperationContext.Current.Host;
host.Description.Endpoints[0].Behaviors.Add(new SilverlightFaultBehavior());

but it does not seem to have any effect. Unable to trigger endpoint behavior.

So, is it possible to add endpoint behavior to the WCF service supported by IIS?

+3
1

ServiceHost ( ). . ServiceHost , IIS, ServicHostFactory, .svc. - custom ServiceHostFactory, CreateServiceHost. .

+2

All Articles