Josh
Josh

Reputation: 13818

How to override the ServiceHost in WCF?

The communication object, ExtendingWCFwithServiceHost.clsMyOwnHost, has overridden the virtual function OnOpening but it does not call version defined in the base class.

I'm getting this error while overriding the OnOpening method of the ServiceHost class.

Upvotes: 0

Views: 1042

Answers (1)

Lee
Lee

Reputation: 144136

The error message explains the problem - you are overriding the OnOpening method but are not calling the base implementation. Your override should look like this:

protected override OnOpening()
{
    //additional processing
    base.OnOpening();
}

This page explains the ICommunicationObject state machine and says:

While System.ServiceModel.Channels.CommunicationObject.OnOpen(System.TimeSpan), System.ServiceModel.Channels.CommunicationObject.OnClose(System.TimeSpan), and System.ServiceModel.Channels.CommunicationObject.OnAbort have no default implementation, the other callbacks do have a default implementation which is necessary for state machine correctness. If you override those methods be sure to call the base implementation or correctly replace it.

Upvotes: 2

Related Questions