1

What I am trying to do is have a wcf duplex service that multiple clients register to. When a client calls the service, the other clients are notified of the call.

Right now, I have a Silverlight app that calls a wcf duplex service. On the first call everything is working correctly including duplex communication. On the second call to the service I am getting a :

The communication object, System.ServiceModel.Channels.ClientPollingDuplexSessionChannel, cannot be used for communication because it is in the Faulted state.

My service has 2 different methods; RegisterClient and ReassignOwner. If I call the same method twice or both method once in any order I am still getting this error.

After researching on the subject I thought it might be a timeout problem. I checked what the default timeout value was and it's 10 minutes. I do both calls within the span of 2-3 minutes tops. I have also increased the Inactivity timeout and the Receive timeout to 4 hours just to be sure and I am still getting this problem.

Next, I thought my service might be generating an exception which would cause the client to go in a faulted state. To test this, I have put try/catch statements in the 2 methods of my service and ran the program in debug mode. I did not catch any exception. I also tried commenting out all the code from those 2 methods (so no exception can be generated) and just calling those 2 empty methods and I still got the exception.

By reading other related post here on SO, I decided to try WCF tracing. I enabled it in my web.config and set the switch value to Warning. I get 2 warnings:

Description Faulted System.ServiceModel.Channels.ServicePollingDuplexSessionChannel
Description Faulted System.ServiceModel.Channels.ServiceChannel

Here is how my service is defined in the code behind .svc.cs file:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, AutomaticSessionShutdown = false)] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NotificationService : BaseService, INotificationDuplexService

In my service contract my methods both have the following attributes:

[OperationContract(AsyncPattern = true, IsOneWay = true,
                   Action = "http://www.abc.org/NotificationDuplex/INotificationDuplexService/MethodName")]

Both my methods are implemented in an async fashion with a Begin and an End method.

Here is how I invoke my methods

base.InvokeAsync(this.onBeginRegisterClientDelegate, new object[] {
                    id}, this.onEndRegisterClientDelegate, this.onRegisterClientCompletedDelegate, userState);

Anybody know why this is happening or have any clue to how I could continue trying to solve this problem ?

Gilles
  • 4,619
  • 4
  • 28
  • 62

3 Answers3

2

Does your ServiceContract require a CallbackContract? If so, I suggest that you read about callback reentrancy here - it's a good description of how WCF can proactively fault your communication channels to prevent a deadlock when you are using callbacks, and what you should do to prevent it.

PaulF
  • 1,085
  • 7
  • 10
  • My ServiceContract does indeed require a CallBackContract. I read the article you linked. I changed my ConcurencyMode to reentrant as sugested but it did not have any effect to the problem at hand. The article also mentioned another solution which I am currently investigating. – Gilles Mar 03 '11 at 13:55
  • Did you specify both `ServiceBehavior` and `CallbackBehavior` as `ConcurrencyMode.Reentrant`? – PaulF Mar 03 '11 at 16:07
1

Another solution which I have seen referenced and I implemented myself is to set up a "heartbeat." I have my configuration set to MultipleMessagesPerPoll, and the service keeps running without a problem because I have the client pinging the server at least once every 9 seconds. That seemed to be a bit of a magic number -- after nine seconds the channel times out and goes into a faulted state. Just set up a thread to ping the service (using a method called ping or something) and the service can respond back to the client with a "pong."

Agree that this problem does not seem to be a problem on Chrome or other browsers.

0

Finally I have found the awnser in a similar question : Silverlight PollingDuplex InnerChannel faulted with multipleMessagesPerPoll (serverPollTimeout)

It seems there is a bug when you set the PollingDuplexHttpBinding to PollingDuplexMode.MultipleMessagesPerPoll and you run your application under IE 8 (other browsers aren't affected).

The solution is to put the PollingDuplexMode to SingleMessagePerPoll which is less performant but focntionnal in IE8.

Community
  • 1
  • 1
Gilles
  • 4,619
  • 4
  • 28
  • 62