开发者

Why does my Wcf Duplex service gets in faulted state after first call to the service?

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 a开发者_高级运维nd 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 ?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜