Dealing with WCF service restart on client-side
Asked Answered
C

2

8

I've got a GUI client which is running against a WCF services hosted as a Windows service on a server box. The WCF service is running in PerCall InstanceContextMode, and the client has a singleton instance of the service client and I want to avoid reinstantiating the singleton on every call as it makes life difficult for the many asynchronous calls I have.

The problem for me is, after the Windows service is restarted, everytime the client makes a call it gets an exception message like this:

This channel can no longer be used to send messages as the output session was auto-closed due to a server-initiated shutdown. Either disable auto-close by setting the DispatchRuntime.AutomaticInputSessionShutdown to false, or consider modifying the shutdown protocol with the remote server.

What's the best way to get around this? I can put try-catch clauses around all the calls to the service client and reinstantiate the singleton instance on communication exceptions but that will involve a lot of boilerplate code..

Cretonne answered 31/12, 2009 at 12:27 Comment(0)
A
9

The best would be to avoid the exceptions on the server all together. If a WCF Server encounters an exception that is not being caught and handled, it will "fault" the channel, rendering it useless.

On the server side, you can implement the IErrorHandler interface and catch .NET exceptions, turning them into SOAP faults which will be handed back to the client more gracefully, without faulting the channel.

That way, you can catch all .NET exceptions on the server, and convert them into interoperable SOAP faults which will not cause these problems.

For more information, see:

Apuleius answered 31/12, 2009 at 12:56 Comment(2)
The problem with this ProtocolException is that the channel state is still "Opened", not "Faulted", and it is very hard to notice that it is in fact unusable.Quadruped
And what does one do when the WCF service is hosted in IIS and rather than being restarted due to an exception, the service is restarted to having been re-deployed?Simplicidentate
M
0

You can take a look at this to perhaps avoid some of that boilerplate code:

http://wcfproxygenerator.codeplex.com

Marion answered 31/12, 2009 at 18:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.