1: public class InvocationConfirmationInteractiveChannelInitializer : IInteractiveChannelInitializer
2: {
3: public const string ConfirmMessage = "程序执行过程涉及到WCF服务调用,是否继续?";
4: public IAsyncResult BeginDisplayInitializationUI(IClientChannel channel, AsyncCallback callback, object state)
5: {
6: bool cancel = MessageBox.Show(ConfirmMessage, "WCF服务调用确认", MessageBoxButtons.YesNo) == DialogResult.No;
7: return new SimpleAsynsResult(cancel);
8: }
9:
10: public void EndDisplayInitializationUI(IAsyncResult result)
11: {
12: SimpleAsynsResult asyncResult = (SimpleAsynsResult)result;
13: if((bool)asyncResult.AsyncState)
14: {
15: throw new InvocationCancelException("WCF服务调用被取消");
16: }
17: }
18: }
19:
20: public class SimpleAsynsResult:IAsyncResult
21: {
22: public SimpleAsynsResult(object state)
23: {
24: this.AsyncState = state;
25: }
26:
27: public object AsyncState { get; private set; }
28: public WaitHandle AsyncWaitHandle { get; private set; }
29: public bool CompletedSynchronously
30: {
31: get { return true; }
32: }
33: public bool IsCompleted
34: {
35: get { return true; }
36: }
37: }