I created a custom ServiceHost that I would like to use to automatically add a message inspector to each service endpoint that runs on it. I created a MessageInspector that implements IDispatchMessageInspector and IClientMessageInspector and found the following code that should add it to each endpoint:
foreach (ChannelDispatcher channel in this.ChannelDispatchers) {
foreach (EndpointDispatcher endpoint in channel.Endpoints) {
endpoint.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector());
}
}
The problem I am facing is that the ChannelDispatchers collection is empty until servicehost is open, which means that I cannot run this code in the constructor. I created an event handler for the Opened event and used this code instead, but then I get the following error when trying to add an endpoint:
This value cannot be changed after a ServiceHost has been opened
It seems like I got into some kind of Catch 22, is this the function I'm looking for in WCF?
Thank,
Mike
source
share