I have successfully implemented the WCF callback template in my code, and now I want to implement an asynchronous callback. Here is my interface 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); }
To use a synchronous callback, I declared my channel and endpoint as follows:
DuplexChannelFactory<IMessage> dcf = new DuplexChannelFactory<IMessage>(new InstanceContext(this), "WSDualHttpBinding_IMessage"); <endpoint address="net.tcp://localhost:8731/Message/" binding="netTcpBinding" contract="WCFCallbacks.IMessage" name="WSDualHttpBinding_IMessage">
I'm having trouble getting the right combination of endpoint and channel to use asynchronous callback. Can someone point me in the right direction?
In addition, if the following line of code is executed:
OperationContext.Current.GetCallbackChannel<IAsyncMessageCallback>();
I get the following error:
Unable to cast transparent proxy to type 'WCFCallbacks.IAsyncMessageCallback'
source share