好的,我明白了。
通过提高回调 ServiceB 至 ServiceA 我在不同的OperationContext中。这个上下文是完全不同的线程,所以与它没有任何联系 Client 而是获得了OperationContext的一部分 ServiceB 。
ServiceB
ServiceA
Client
我向CallbackHandler添加了新成员 ServiceA 指向OperationContext。为此,我在创建期间传递当前上下文 ServiceB 运用 DuplexChannelfactory 。此上下文是正确的,可用于将回调引回 Client 。我希望代码让它变得可以理解。
DuplexChannelfactory
的制作 ServiceB 在 ServiceA :
InstanceContext context = new InstanceContext(new CallbackHandler(OperationContext.Current)); ChannelFactory<IService> factory = new DuplexChannelFactory<IServiceB>(context, binding, address); IServiceB service = factory.CreateChannel();
CallbackHandler of ServiceA :
public class CallbackHandler : IServiceBCallback { OperationContext _context; public CallbackHandler(OperationContext context) { _context = context; } public void TestProgress(string msg) { IServiceACallback callback = _context.GetCallbackChannel<IServiceACallback>(); callback.TestProgress(msg); } }