I knew that this answer will come ;) I should have written that I'm
using ninject and not windsor :( Any thoughts without facility?

Daniel

On Aug 11, 11:42 pm, Krzysztof Koźmic <[email protected]>
wrote:
>   Wcf facility already handles that OOTB, without any need for code
> generation.
>
> On 12/08/2010 1:43 AM, LOBOMINATOR wrote:
>
> > Hello
>
> >http://wcfproxygenerator.codeplex.com/releases/view/28579
> > The sample has an Abstract class ExceptionHandlingProxyBase<T>  which
> > does implement logic to close and regenerate WCF proxies when an
> > exception occurs.
>
> >      [ServiceContract]
> >      public interface IFoo
> >      {
> >       [OperationContract]
> > void Bar();
> > int BarWithReturn();
> > void BarWithParam(int yeah);
> >      }
>
> > How can I use dynamic proxy to generate a class which looks like this:
>
> > public class Proxy : ExceptionHandlingProxyBase<IFoo>, IFoo
> > {
> > public void Bar() {
> >     base.Invoke("Bar");
> > }
> > public int Bar() {
> >     return base.Invoke("Bar");
> > }
> > public void BarWithParam(int yeah) {
> > base.Invoke("BarWithParam", yeah);
> > }
> > }
>
> > Here the ExceptionHandlingProxyBase
>
> >     public class ExceptionHandlingProxyBase<T>  : ICommunicationObject,
> > IDisposable
> >           where T : class
> >      {
> >          // state
> >          private bool IsOpened { get; set; }
> >          public bool IsDisposed { get; private set; }
>
> >          // lock
> >          private object m_channelLock = new object();
> >          private bool m_isInitialized = false;
> >          private bool m_isProxyCreated = false;
> >          private ManualResetEvent m_proxyRecreationLock = new
> > ManualResetEvent(true);
> >          protected int m_proxyRecreationLockWait = 1000;
>
> >          // channel
> >          private ChannelFactory<T>  m_channelFactory = null;
> >          private T m_channel = default(T);
>
> >          #region Constructors
>
> >          public ExceptionHandlingProxyBase()
> >          {
> >          }
>
> >          public ExceptionHandlingProxyBase(string
> > endpointConfigurationName)
> >          {
> >              Initialize(endpointConfigurationName);
> >          }
>
> >          protected virtual void Initialize(string
> > endpointConfigurationName)
> >          {
> >              if (this.m_isInitialized) throw new
> > InvalidOperationException("Object already initialized.");
> >              this.m_isInitialized = true;
>
> >              m_channelFactory = new
> > ChannelFactory<T>(endpointConfigurationName);
> >          }
>
> >          public ExceptionHandlingProxyBase(string
> > endpointConfigurationName, string remoteAddress)
> >          {
> >              Initialize(endpointConfigurationName, remoteAddress);
> >          }
>
> >          protected virtual void Initialize(string
> > endpointConfigurationName, string remoteAddress)
> >          {
> >              if (this.m_isInitialized) throw new
> > InvalidOperationException("Object already initialized.");
> >              this.m_isInitialized = true;
>
> >              m_channelFactory = new
> > ChannelFactory<T>(endpointConfigurationName, new
> > EndpointAddress(remoteAddress));
> >          }
>
> >          public ExceptionHandlingProxyBase(Binding binding,
> > EndpointAddress remoteAddress)
> >          {
> >              Initialize(binding, remoteAddress);
> >          }
>
> >          protected virtual void Initialize(Binding binding,
> > EndpointAddress remoteAddress)
> >          {
> >              if (this.m_isInitialized) throw new
> > InvalidOperationException("Object already initialized.");
> >              this.m_isInitialized = true;
>
> >              m_channelFactory = new ChannelFactory<T>(binding,
> > remoteAddress);
> >          }
>
> >          #endregion
>
> >          #region Proxy creation
>
> >          public event EventHandler AfterRecreateProxy;
>
> >          protected virtual void CreateProxy()
> >          {
>
> >              lock (this.m_channelLock)
> >              {
> >                  if (this.m_isProxyCreated) throw new
> > InvalidOperationException("Proxy already created.");
> >                  CreateInnerChannel();
> >                  this.m_isProxyCreated = true;
>
> >              }
> >          }
>
> >          protected virtual void RecreateProxy()
> >          {
> >              lock (this.m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  CreateInnerChannel();
>
> >                  if (AfterRecreateProxy != null)
> >                      AfterRecreateProxy(this, null);
> >              }
> >          }
>
> >          private void CreateInnerChannel()
> >          {
> >              lock (this.m_channelLock)
> >              {
> >                  if (m_channelFactory == null)
> >                      throw new InvalidOperationException("Proxy
> > invalid. This occurs when you use the default constructor.");
>
> >                  m_channel = m_channelFactory.CreateChannel();
>
> >                  ICommunicationObject co = m_channel as
> > ICommunicationObject;
> >                  co.Faulted += InnerChannel_Faulted;
> >                  co.Closed += InnerChannel_Closed;
> >                  co.Closing += InnerChannel_Closing;
> >                  co.Opened += InnerChannel_Opened;
> >                  co.Opening += InnerChannel_Opening;
> >              }
> >          }
> >          #endregion
>
> >          #region Communication events
>
> >          private void InnerChannel_Opening(object sender, EventArgs e)
> >          {
> >              lock (m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  if (this.Opening != null)
> >                      this.Opening(sender, e);
> >              }
> >          }
>
> >          private void InnerChannel_Opened(object sender, EventArgs e)
> >          {
> >              lock (m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  if (this.Opened != null)
> >                      this.Opened(sender, e);
> >              }
> >          }
>
> >          void InnerChannel_Closing(object sender, EventArgs e)
> >          {
> >              lock (m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  if (this.Closing != null)
> >                      this.Closing(sender, e);
> >              }
> >          }
> >          private void InnerChannel_Closed(object sender, EventArgs e)
> >          {
> >              lock (m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  try
> >                  {
> >                      this.m_proxyRecreationLock.Reset(); // will stop
> > other threads from trying to Invoke() while recreating the proxy
>
> >                      if (this.Closed != null)
> >                          this.Closed(sender, e);
>
> >                      OnClosed();
> >                  }
> >                  finally
> >                  {
> >                      this.m_proxyRecreationLock.Set(); // will stop
> > other threads from trying to Invoke() while recreating the proxy
> >                  }
>
> >              }
>
> >          }
> >          protected virtual void OnClosed()
> >          {
> >              lock (this.m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  this.Abort();
> >                  RecreateProxy();
>
> >              }
> >          }
>
> >          private void InnerChannel_Faulted(object sender, EventArgs e)
> >          {
> >              lock (m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  try
> >                  {
> >                      this.m_proxyRecreationLock.Reset(); // will stop
> > other threads from trying to Invoke() while recreating the proxy
>
> >                      if (this.Faulted != null)
> >                          this.Faulted(sender, e);
>
> >                      OnFaulted();
> >                  }
> >                  finally
> >                  {
> >                      this.m_proxyRecreationLock.Set(); // will stop
> > other threads from trying to Invoke() while recreating the proxy
> >                  }
> >              }
>
> >          }
> >          protected virtual void OnFaulted()
> >          {
> >              lock (this.m_channelLock)
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  this.Abort();
> >                  RecreateProxy();
> >              }
> >          }
>
> >          #endregion
>
> >          # region Channel Properties
> >          public IClientChannel InnerChannel
> >          {
> >              get
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  return (IClientChannel)m_channel;
> >              }
> >          }
>
> >          public ClientCredentials ClientCredentials
> >          {
> >              get
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  return m_channelFactory.Credentials;
> >              }
> >          }
>
> >          public ServiceEndpoint Endpoint
> >          {
> >              get
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  return m_channelFactory.Endpoint;
> >              }
> >          }
>
> >          public CommunicationState State
> >          {
> >              get
> >              {
> >                  if (this.IsDisposed) throw new
> > InvalidOperationException("Cannot use disposed object.");
>
> >                  IChannel channel = (IChannel)m_channel;
> >                  if (channel == null)
> >                      return CommunicationState.Created;
>
> >                  return channel.State;
> >              }
> >          }
>
> >          #endregion
>
> >          #region ICommunicationObject Members
>
> ...
>
> read more >>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to