简体   繁体   中英

WCF callback channel abort exception

I implemented publisher-subscriber mechanism with 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:

     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 ,

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 ...

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. You can not send data from the service to client, or vice versa if you kill the service or the client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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