WCF Event Announcement

I see that WCF does not directly use events and instead uses OneWay delegate calls, but can anyone show me a simple example of how to do this?

Here is what I installed right now:

    [OperationContract(IsOneWay = true)]
    void OnGetMapStoryboardsComplete(object sender, List<Storyboard> results);
+3
source share
1 answer

Assuming your contractual contract interface is called IMyServiceCallback, your service would execute the following code when it wants to raise an event:

IMyServiceCallback callback = OperationContext.Current.GetCallbackChannel<IMyServiceCallback>();
callback.OnGetMapStoryboardsComplete(...);

I found this article very helpful. It describes a system of transient events and a permanent system of events, each of which must satisfy any scenario of events, IMO.

NTN

To set up a callback contract:

interface IMyServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void OnGetMapStoryboardsComplete(object sender, List<Storyboard>);
}

, :

[ServiceContract(CallbackContract = typeof(IMyServiceCallback))]
interface IMyService
{
    // ...
}

, . , IMyServiceCallback:

class EventHandler : IMyServiceCallback
{
    public void OnGetMapStoryBoardsComplete(object sender, List<Storyboard>)
    {
        // Do whatever needs to be done when the event is raised.
    }
}

, InstanceContext, , :

EventHandler eventHandler = new EventHandler();
MyServiceClient client = new MyServiceClient(new InstanceContext(eventHandler));

?

+7

All Articles