1
votes

I have a WPF application that uses WCF service. Service instance context mode is set to PerSession. In the service there is a method with a callback to the client that sends messages received from external queue.

When I start new service and run application everything works fine, callback channel has open state. When I close application and run it again callback always throws 'Cannot access disposed object' error and has Closed state.

To connect to the service form client side I use DuplexChannelFactory, after closing application channel and channel facotry are disposed. I can see in logs that Closing and Closed events were invoked. I thought that maybe service is holding last session or when I re-run the application it connects to the same channel that was closed. I checked session Ids, and they are different. UUid is the same.

For me it looks like client app is using the same channel after restart. Is service side caching something about channels?

I hope I gave enough explanation. I will provide more information if needed. Any ideas how to solve this issue?

Thanks

1
Have you confirmed that the error you are getting is not coming from the WCF service itself? Maybe there's something that happening inside the WCF service after the first disconnect that causes an exception on the next connection. Also, are you getting the error on initialization of the WCF service, or when you actually try and call a function?Ben Abraham
Do you have a full stack trace available?Dan Field
This behaviour is by design. The callback channel will close when the client closes.tom redfern
Could you show piece of server code that remembers callbacks and sends messages?Igor Labutin

1 Answers

1
votes

I have experienced a similar error where the issue turned out to be a too limited "request limit" for the Internet Information Services (IIS) application pool, which caused the application pool to recycle after every request. Simply changing the "request limit" value, either to 0 (i.e. unlimited) or a higher number, fixed the issue.

To change the "request limit":

  1. Open IIS manager.
  2. Expand the host-machine and click "application pools".
  3. Right-click the application pool running your web-service and choose "advanced settings" from the context-menu.
  4. Scroll down to the "recycling" section, where you will find "request limit".
  5. Specify a new "request limit".
  6. Click "OK".