简体   繁体   English

WCF回调通道中止异常

[英]WCF callback channel abort exception

I implemented publisher-subscriber mechanism with WCF. 我用WCF实现了发布者-订阅者机制。

this is how I subscribe for callbacks : 这就是我订阅回调的方式:

public delegate void AsyncResponseEventHandler(AsyncResponse asyncResponse); 
public static event AsyncResponseEventHandler AsyncResponseEvent;       
public static IMyEvents Subscriber;        
public  void SubscribeEvent()        
{            
Subscriber = OperationContext.Current.GetCallbackChannel<IMyEvents>();            
AsyncResponseEvent += new AsyncResponseEventHandler (Subscriber.AsyncResponseCallBack);        
}         
public static void RaiseAsyncResponse(AsyncResponse asyncResponse)    
{         
   try 
           {                
        AsyncResponseEvent.Invoke(asyncResponse);
           }            
catch (Exception ex)  {throw;}    
}     

and also this is the MySubscriber Class code: 这也是MySubscriber类代码:

     public class MySubscriber : IMyEvents
    {


 public void AsyncResponseCallBack(AsyncResponse asyncResponse)
        {

            AsyncResponseEventArgs e = new AsyncResponseEventArgs()
            {
                Response = asyncResponse
            };
            OnAsyncResponseReceived(this, e);

        }
    }

I use RaiseAsyncResponse method to raise callback to client , 我使用RaiseAsyncResponse方法引发对客户端的回调,

when service host is windows service and I start the service and I start debugging , everything works fine for the first time , but when I stop the client application and restart debugging with out restarting the windows service , I face the exception: The communication object, System.ServiceModel.Channels.ServiceChannel , cannot be used for communication because it has been Abort ... 当服务主机是Windows服务并且我启动服务并开始调试时,一切都第一次正常运行,但是当我停止客户端应用程序并在不重新启动Windows服务的情况下重新启动调试时,我遇到了一个例外:通信对象, System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它已中止...

why the callback channel is aborted? 为什么回调通道被中止? please help me out ... :( 请帮我... :(

Because "but when I stop the client application" is the answer. 因为“但是当我停止客户端应用程序时”才是答案。 Soon as you stop the client application, System.ServiceModel will release the hold on the channel. 停止客户端应用程序后,System.ServiceModel很快就会释放该通道上的保留。 You can not send data from the service to client, or vice versa if you kill the service or the client. 如果您终止了服务或客户端,则无法将数据从服务发送至客户端,反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM