Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2007

Tip: Looking for answers? Try searching our database.

Singleton instance of web service?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
davebythesea - 21 Dec 2007 16:10 GMT
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
davebythesea - 21 Dec 2007 17:00 GMT
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
John Saunders [MVP] - 23 Dec 2007 18:18 GMT
> Hi folks,
>
[quoted text clipped - 14 lines]
> 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.
Signature

--------------------------------------------------------------------------------
John Saunders | MVP - Windows Server System - Connected System Developer


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.