So as to enable aysc callbacks to the clients, I need to add the Begin/End methods to the interface that is defined as the CallbackContract on my service. (I am using a she
When you do GetCallbackChannel you should specify exactly the same type as you specfied in the [ServiceContract] attribute, its strongly typed.
Even if A.IClient and B.IClient have exactly the same code with only namespace changed, those are completely different types from .NET's view.
As DxCK siad the type that is passed to OperationContext.Current.GetCallbackChannel<T
>() must be exactly the same type as you specified in the [ServiceContract] attribute on the interface that the service implements.
However I need to use a different interface for the callbacks so I can add the Begin/End methods needed to support aysc callbacks.
So firstly my new callback interface.
[ServiceContract]
public interface IClientWithAsyncMethods : IClient
{
[OperationContract(
AsyncPattern = true,
Action = "ReceiveMessage",
ReplyAction = "ReceiveMessageResponse")]
IAsyncResult BeginReceiveMessage(SimMessage message,
AsyncCallback callback, object asyncState);
void EndReceiveMessage(IAsyncResult asyncResult);
}
Then need to define a new interface for my service to implment:
[ServiceContract(CallbackContract = typeof(IClientWithAsyncMethods))]
public interface IEngineManagerWithAsyncCallbacks : IEngineManager
{
}
The only change to to refare to the new callback interface as the CallbackContract, this is OK as IClientWithAsyncMethods is a subtype of IClient.
Then the last step is to change the serve implementation to use to the service interface:
<IClientWithAsyncMethods
>() The rest is just calling the aysc method in the normal way.