asp.net mvc - Make WCF client static or use dispose method -


i developing website in mvc asp.net uses wcf service. i'm using wcf client in controller that

public class home : controller {     private serviceclient _client = new serviceclient();      public actionresult index()     {         //code here     } } 

so think 2 options have define it:

1- make client object static

private static serviceclient _client = new serviceclient(); 

2- use idisposable.dispose

public class home : controller, idisposable {     private serviceclient _client = new serviceclient();      protected override void dispose(bool disposing)     {         _client.dispose();         base.dispose(disposing);     } } 

what best option performance ?

both options irrelevant performance point of view. creating wcf channel factories performance "expensive". serviceclient inherits clientbase, channel factory caching. creating clients cheap , that's correct approach: create client, use it, dispose immediately.

the second option therefore correct, if not flaw in wcf client desing. flaw causes cannot rely on client's dispose method handle channel's fault state correctly. issue sure has been covered somewhere else in so. in short, here's how create , dispose wcf client:

var client = new serviceclient(); var success = false; try {     // call client's methods     client.close();     success = true; } {     if (!success)     {         client.abort();     } } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -