Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might be able to use the decorater pattern to handle exceptions with WCF proxies. If this path is open to you, you can consider something like this set-up which will handle the proxy faulting and re-initialise it for callers. Subsequent exceptions will be thrown up to the caller. </p> <pre><code>//Proxy implements this interface IMyService { void MyMethod(); } //Decorator 1 public class MyServiceProxyRetryingDecorator : IMyService { //This is the real proxy that might be faulted private realProxy = new RealProxy(); public void MyMethod() { ReEstablishProxyIfNecessary(); //now just pass the call to the proxy, if it errors again, //do more handling or let the exception bubble up realProxy.MyMethod(); } private void ReEstablishProxyIfNecessary() { if(realProxy.CommunicationState == CommunicationState.Faulted) { realProxy.Abort(); realProxy = new RealProxy(); } } } </code></pre> <p>An different version of the decorator could have the decorator handling your MessageSecurityException, and re-initialising the real proxy when it is caught:</p> <pre><code>//Decorator 2 public class MyServiceProxyExceptionHandlingDecorator : IMyService { //This is the real proxy that might be faulted private realProxy = new RealProxy(); public void MyMethod() { try {realProxy.MyMethod(); } catch (ExceptionYouAreInterestedIn ex) { ReEstablishProxyIfNecessary(); realProxy.MyMethod(); //do it again } } private void ReEstablishProxyIfNecessary() { if(realProxy.CommunicationState == CommunicationState.Faulted) { realProxy.Abort(); realProxy = new RealProxy(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload