chrystad
chrystad

Reputation: 41

What is best practice when instantiating a web service

I have a class library (c#) with many methods that call the same web service (asmx).

What is the best practice for instantiating the web service.

Upvotes: 4

Views: 543

Answers (2)

LiFo
LiFo

Reputation: 128

It seams like a bad practice to make a new instance of the service, hook up complete events each time you have to call a service method

usually i make an instance variable and then instantiate the service in the constructor and hook up all complete events there

and only call the methods when needed this approach works well, except if you do it in an User-control it breaks the Visual Studio Designer

Upvotes: 0

Oded
Oded

Reputation: 499132

What you are instantiating is a local proxy class that calls the service, so it isn't as costly as you may think.

As web services are supposed to be stateless, either method would work. I doubt you will see much of a difference in performance.

Upvotes: 6

Related Questions