大家对WCF 中Call back method 可能都比较难理解,Call back method 回调函数,个人记录些自己的理解和说明
原理 是 这样的 ,客户端先向服务端发送单项的消息 ,服务端接受消息后实例话接口中的上下文 ,再回复给客户端要调用的方法。服务器要实现和Callback接口,在客户端要实现这个接口。下面是要比普通的多实现的多实现的类和接口方法。
Server :ICallback
[ServiceContract]
[OperationContract(IsOneWay = true )]
IService
[ServiceContract(CallbackContract = typeof (ICallback))]
ICallBack call = OperationContext.Current.GetCallbackChannel < ICallBack > ();
Client: new ServiceClient( new InstanceContext( new ClientCallBack())) ;
Class ClinetCallBack ; ICallbck
... {
//this is true to do
}
[ServiceContract]
[OperationContract(IsOneWay = true )]
IService
[ServiceContract(CallbackContract = typeof (ICallback))]
ICallBack call = OperationContext.Current.GetCallbackChannel < ICallBack > ();
Client: new ServiceClient( new InstanceContext( new ClientCallBack())) ;
Class ClinetCallBack ; ICallbck
... {
//this is true to do
}