HighTechTalks DotNet Forums  

Singleton instance of web service?

Dotnet Framework (Webservices) microsoft.public.dotnet.framework.webservices


Discuss Singleton instance of web service? in the Dotnet Framework (Webservices) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
davebythesea
 
Posts: n/a

Default Singleton instance of web service? - 12-21-2007 , 11:10 AM






Hi folks,

I'm just curious if it is possible to create a Singleton instance of a Web
Service? Currently I create my web services in VS 2005, and then in my
applications I add the Web Service via 'Add web Reference', which as you know
doubt no is a great and easy mechanism for getting the proxy class etc.. al
nice and quickly added to the project.

However, say in my project I have two forms, and both use the Web reference.
Instantiating an instance of the web service in each form, and using when
needed, and disposing when finished, must cause a bit of a performance hit
(especially in pocket pc). So I was thinking, how can one create a Singleton
instance of the web Service and use it throughout the application? Or is
there some other mechanism to achieve a similar result?

Thanks for any opinions.
Dav

Reply With Quote
  #2  
Old   
davebythesea
 
Posts: n/a

Default RE: Singleton instance of web service? - 12-21-2007 , 12:00 PM






Hi folks,

I was thinking something maybe like this -

class SingletonService
{
private static SingletonService instance;
private static object padlock = new object();

private Mobile.Service.Service webService = new Mobile.Service.Service();

protected SingletonService()
{
}

public bool fLogin(string username, string password)
{
return webService.fLogin(username, password);
}

public static SingletonService Instance
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new SingletonService();
}
return instance;
}
}
}
}

Any views?

Best,
Dave

Reply With Quote
  #3  
Old   
John Saunders [MVP]
 
Posts: n/a

Default Re: Singleton instance of web service? - 12-23-2007 , 01:18 PM



"davebythesea" <davebythesea (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi folks,

I'm just curious if it is possible to create a Singleton instance of a Web
Service? Currently I create my web services in VS 2005, and then in my
applications I add the Web Service via 'Add web Reference', which as you
know
doubt no is a great and easy mechanism for getting the proxy class etc..
al
nice and quickly added to the project.

However, say in my project I have two forms, and both use the Web
reference.
Instantiating an instance of the web service in each form, and using when
needed, and disposing when finished, must cause a bit of a performance hit
(especially in pocket pc). So I was thinking, how can one create a
Singleton
instance of the web Service and use it throughout the application? Or is
there some other mechanism to achieve a similar result?
In general, I think it would be best to not solve performance problems
before they exist - you might be solving the wrong problem.
--
--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.