C# HOW TO MANAGE WCF SERVICE PROXY LIFECYCLE ON CLIENT SIDE?

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
C#
 1741  View(s)
Ratings:
Rate this:

I have written a WCF service with some regular functionality (add user, remove, search, update...). The implementation of this functionality is in entity framework (with sql DB).

Now I want to use it in the client side. And I have some basic questions:

I have many calls to the WCF methods in the client side - should I try catch every time each call?

Every time I want to call a method, for example AddUser(User user), I need to make an instance of my service, like that:

WcfService client = new WcfService();

client.AddUser(user);

And in another place I write:

WcfService client = new WcfService(); //Again making a new instance...

client.UpdateUser(user);

Should I make one instance for all the application for my wcf service? Or every time to make a new instance before I call to a method? (as in my example above).

Thanks very much !

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: c# how to manage wcf service proxy lifecycle on client side?

    Hi Goti,

    (i)You can make an instance one time for a service, and use the same client whenever you need to make a method call. If you are aborting or closing the connection then you need to create each time.

    (ii)It is better if you use try catch methods in each methods, so it will be easy to close the connection and identify the exceptions.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!