Best Practice for WCF Service Proxy lifetime?

后端 未结 4 568
北海茫月
北海茫月 2020-12-23 17:51

When working with WCF services, is it better to create a new instance of the service every time you use it? Or is it better to create one and re-use it? Why is either appr

4条回答
  •  余生分开走
    2020-12-23 18:48

    One more point to consider is channel faults. By design WCF does not allow to use client proxy after unhandled exception happened.

    IMyContract proxy = new MyContractClient( );
    try
    {
       proxy.MyMethod( );
    }
    catch
    {}
    
    //Throws CommunicationObjectFaultedException
    proxy.MyMethod( );
    

提交回复
热议问题