views:

39

answers:

1

Hello,

I am using the following code in my Global.asax.cs file:

public static readonly IMyCommunicationService GlobalCommunicationChannel =
        new ChannelFactory<IMyCommunicationService>("NetTcpBinding_IMyCommunicationService").CreateChannel();

From every website I am accessing the static var "GlobalCommunicationChannel".

That is working very well so far. But sometimes, in production environment, I am getting an CommunicationObjectFaultedException. It says that I can not use my GlobalCommunicationChannel object as the object "System.ServiceModel.Channels.ServiceChannel" is in faulted-state.

I get no more information than that. After some minutes it is working again. Don't know why. I think the connection is re-established or something like that.

What causes this error?
Is there a way to avoid this error in future without adding a try/catch and a retry everywhere?

Thank you very much in advance for your answer!

A: 

Check your SessionMode value:

By default, the value of this property is Allowed, which means that if a client uses a session-based binding with a WCF service implementation, the service establishes and uses the session provided. (source)

In your service contract, try setting the session to NotAllowed.

[ServiceContract(SessionMode=SessionMode.NotAllowed)]

By default, the maximum number of sessions a service host accepts is 10. So you might check to see if your problem can be replicated in relation to 10 sessions.

Larsenal
Hello again. I have tried it, but now I get the following error:Contract does not allow Session, but Binding 'NetTcpBinding' does not support Datagram or is not configured properly to support it.
Chris
I will try [ServiceContract(SessionMode = SessionMode.Required)]instead.
Chris
No, this is also not working :(
Chris