WCF Callback Interface - Who Closes a Channel

I have problems / questions blocking the reverse / duplex communication channel. Here are my prototype WCF interfaces:

[ServiceContract(CallbackContract = typeof(IMyInterfaceCallback))] public interface IMyInterface { [OperationContract] void StartWork(); } public interface IMyInterfaceCallback { [OperationContract(IsOneWay = true)] void WorkFeedback(); } 

On the client side, I create my WCF interface with:

 DuplexChannelFactory<IMyInterface> dcf = new DuplexChannelFactory<IMyInterface>(implOfIMyInterfaceCallback, customBinding, ea); IMyInterface myInterface = dcf.CreateChannel(); 

On the server side, I use

 OperationContext.Current.GetCallbackChannel<IMyInterfaceCallback>(); 

to get a callback pointer, which can then be used to communicate with the client.

Now my questions are:

  • Who should close the communication channel? Client or server
  • What communication objects need to be closed? Source interface (IMyInterface) or callback interface (IMyInterfaceCallback) or both.

I tried to close the server-side callback interface while the server knew that it would no longer make callbacks. Using ICommunicationObject :: Close on the callback interface, however, resulted in a one-minute lock operation.

Closing on the client side, in my opinion, is wrong, since the client does not know if there are more callbacks.

Thanks for any help. Franc

PS: This seems to be a very simple question, but so far I have not found useful information when searching through google or in stackoverflow ...

+7
source share
2 answers

DuplexChannel uses a TCP connection under the hood and that it emulates bidirectional communication. However, the client always opens this connection, so it is also responsible for closing it (think in the TCP socket). Therefore, you must use the IMyInterface client interface (which comes from IClientChannel) to close it.

Relations Pablo.

+3
source

The client must close the service channel (as usual).

The return channel received via GetCallbackChannel should NOT be closed in my experience (see this related question of mine: Do I need to close and / or delete callback channels received through OperationContext.Current.GetCallbackChannel? )

When closing the channel, you should use the preferred template:

 Try channel.Close() Catch ex As Exception channel.Abort() End Try 

Since the client (usually) cannot know whether any messages continue to be executed when trying to close the channel, which will lead to an exception.

+6
source

All Articles