ChannelFactory.Close VS IClientChannel.Close

前端 未结 4 438
灰色年华
灰色年华 2020-12-13 05:02

Consider the following code which is typcial of many ChannelFactory examples:

WSHttpBinding myBinding = new WSHttpBinding();
EndpointAddress myEndpoint = new         


        
4条回答
  •  我在风中等你
    2020-12-13 05:24

    As you know, the ChannelFactory creates the client channel based on configuration. You may want to create multiple client channels from an existing factory (to the same endpoint as that is locked). If you're done using the factory to create channels, there is no reason not to close it.

    But, why might you want to keep it open? Here's an interesting article on WCF clients that says:

    Checking the value of the System.ServiceModel.ICommunicationObject.State property is a race condition and is not recommended to determine whether to reuse or close a channel.

    Rather than reuse a channel, you might want to simply create a new one with the channel factory. More on the client architecture is here.

提交回复
热议问题