WCF客户端关闭代码

 

Close不一定会成功,所以需要Abort

  1. ChannelFactory channel = new ChannelFactory<IService1>("bindingName");
  2. IService1 client = channel.CreateChannel();
  3. try
  4. {
  5.     client.Say("Hello, world!");
  6.     client.Close();
  7. }
  8. catch (CommunicationException e)
  9. {
  10.     //...
  11.     client.Abort();
  12. }
  13. catch (TimeoutException e)
  14. {
  15.     //...
  16.     client.Abort();
  17. }
  18. catch (Exception e)
  19. {
  20.     //...
  21.     client.Abort();
  22. }

你可能感兴趣的:(WCF)