title: WCF asynchronous callback
body: <p>I have successfully implemented the WCF callback pattern in my code and now I want to implement an asynchronous callback. Here is my interface code:</p>
  
  <pre><code>[ServiceContract(Name = "IMessageCallback")]
  public interface IMessageCallback
  {
    [OperationContract(IsOneWay = true)]
    void OnMessageAdded(string message, DateTime timestamp);
  }
  
  [ServiceContract(Name="IMessageCallback")]
  public interface IAsyncMessageCallback
  {
    [OperationContract(AsyncPattern = true)]
    IAsyncResult BeginOnMessageAdded(string msg, DateTime timestamp, AsyncCallback callback, object asyncState);
    void EndOnMessageAdded(IAsyncResult result);
  }
  
  [ServiceContract(CallbackContract = typeof(IMessageCallback))]
  public interface IMessage
  {
    [OperationContract]
    void AddMessage(string message);
  }
  </code></pre>
  
  <p>To use the synchronous callback I declared my channel and endpoint like so:</p>
  
  <pre><code>DuplexChannelFactory&lt;IMessage&gt; dcf = new DuplexChannelFactory&lt;IMessage&gt;(new InstanceContext(this), "WSDualHttpBinding_IMessage");
  &lt;endpoint address="net.tcp://localhost:8731/Message/"
              binding="netTcpBinding"
              contract="WCFCallbacks.IMessage" name="WSDualHttpBinding_IMessage"&gt;
  </code></pre>
  
  <p>I am having trouble getting the right combination of endpoint and channel to utilize the asynchronous callback. Can someone point me in the right direction?</p>
  
  <p>In addition when the following line of code is executed:</p>
  
  <pre><code>OperationContext.Current.GetCallbackChannel&lt;IAsyncMessageCallback&gt;();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Unable to cast transparent proxy to type 'WCFCallbacks.IAsyncMessageCallback'
  </code></pre>