Web services start event and dll

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shashwat_k11@yahoo.com

    #1

    Web services start event and dll

    Hi,

    I am writing web service and I want to read a file only once when I
    start the web service. How can I do that? Which event fires exactly
    onece when we launch web service?



    I am reading a xml file in the Init() so whenever the web service is
    invoked, it is reading that file. This is what I want to avoid. Where
    can I write the code so that the file gets read only once? Also where
    should I place the dll so that it will be accessible as long as the
    web service is running.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Web services start event and dll

    I'm assuming that you need to read the XML file for some class that
    offers up the details in that file (which is treated as read-only, from what
    I can tell).

    The best way to do this is to create a static constructor for the class
    which utilizes the file, and then load the file in the static constructor
    into a static variable (or load the information in the file into whatever
    static variables you want) and then access those from your class instances.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <shashwat_k11@y ahoo.comwrote in message
    news:1194474386 .554810.164790@ z9g2000hsf.goog legroups.com...
    Hi,
    >
    I am writing web service and I want to read a file only once when I
    start the web service. How can I do that? Which event fires exactly
    onece when we launch web service?
    >
    >
    >
    I am reading a xml file in the Init() so whenever the web service is
    invoked, it is reading that file. This is what I want to avoid. Where
    can I write the code so that the file gets read only once? Also where
    should I place the dll so that it will be accessible as long as the
    web service is running.
    >

    Comment

    • shashwat_k11@yahoo.com

      #3
      Re: Web services start event and dll

      Thanks for your reply.

      I am reading that file in a static variable and I am checking that
      static variable before reading that file again. Everything works fine
      for 10 min. or so.

      But if I do not invoke the web services for more than 10 min, then I
      guess the garbage collector runs and static variable looses all the
      values stored in it. So I read that file again. Now, reading that file
      is very expensive. So I want to reduce no. of times that I am reading
      the file.

      Where can I write the code so that it will be run exactly once and
      will be alive as long as that session is alive.




      On Nov 7, 4:53 pm, "Nicholas Paldino [.NET/C# MVP]"
      <m...@spam.guar d.caspershouse. comwrote:
      I'm assuming that you need to read the XML file for some class that
      offers up the details in that file (which is treated as read-only, from what
      I can tell).
      >
      The best way to do this is to create a static constructor for the class
      which utilizes the file, and then load the file in the static constructor
      into a static variable (or load the information in the file into whatever
      static variables you want) and then access those from your class instances.
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - m...@spam.guard .caspershouse.c om
      >
      <shashwat_...@y ahoo.comwrote in message
      >
      news:1194474386 .554810.164790@ z9g2000hsf.goog legroups.com...
      >
      >
      >
      Hi,
      >
      I am writing web service and I want to read a file only once when I
      start the web service. How can I do that? Which event fires exactly
      onece when we launch web service?
      >
      I am reading a xml file in the Init() so whenever the web service is
      invoked, it is reading that file. This is what I want to avoid. Where
      can I write the code so that the file gets read only once? Also where
      should I place the dll so that it will be accessible as long as the
      web service is running.- Hide quoted text -
      >
      - Show quoted text -

      Comment

      • Ashot Geodakov

        #4
        Re: Web services start event and dll

        Try to log Application_OnE nd event in your Global.asax.

        I have a asp.net server that is run on a shared hosting (GoDaddy). Every now
        and then their IIS unloads my application for no apparent reason. I do store
        some data in static variables, and eventually they get lost. I have to back
        them up in each Application_OnE nd() and restore them in each
        Application_OnS tart(). But as long as your app is alive/loaded, there
        shoudn't be any problem with your variables.

        Again, try and see if the reason for lost data is that your app gets
        unloaded (log every Application_OnE nd). If that's the case, you need to come
        up with some other ways of storing your data. Database vs File would be
        another option.



        <shashwat_k11@y ahoo.comwrote in message
        news:1194477967 .141993.72290@z 9g2000hsf.googl egroups.com...
        Thanks for your reply.
        >
        I am reading that file in a static variable and I am checking that
        static variable before reading that file again. Everything works fine
        for 10 min. or so.
        >
        But if I do not invoke the web services for more than 10 min, then I
        guess the garbage collector runs and static variable looses all the
        values stored in it. So I read that file again. Now, reading that file
        is very expensive. So I want to reduce no. of times that I am reading
        the file.
        >
        Where can I write the code so that it will be run exactly once and
        will be alive as long as that session is alive.
        >
        >
        >
        >
        On Nov 7, 4:53 pm, "Nicholas Paldino [.NET/C# MVP]"
        <m...@spam.guar d.caspershouse. comwrote:
        > I'm assuming that you need to read the XML file for some class that
        >offers up the details in that file (which is treated as read-only, from
        >what
        >I can tell).
        >>
        > The best way to do this is to create a static constructor for the
        >class
        >which utilizes the file, and then load the file in the static constructor
        >into a static variable (or load the information in the file into whatever
        >static variables you want) and then access those from your class
        >instances.
        >>
        >--
        > - Nicholas Paldino [.NET/C# MVP]
        > - m...@spam.guard .caspershouse.c om
        >>
        ><shashwat_...@ yahoo.comwrote in message
        >>
        >news:119447438 6.554810.164790 @z9g2000hsf.goo glegroups.com.. .
        >>
        >>
        >>
        Hi,
        >>
        I am writing web service and I want to read a file only once when I
        start the web service. How can I do that? Which event fires exactly
        onece when we launch web service?
        >>
        I am reading a xml file in the Init() so whenever the web service is
        invoked, it is reading that file. This is what I want to avoid. Where
        can I write the code so that the file gets read only once? Also where
        should I place the dll so that it will be accessible as long as the
        web service is running.- Hide quoted text -
        >>
        >- Show quoted text -
        >
        >

        Comment

        • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

          #5
          RE: Web services start event and dll

          If you have items that you need read when the application starts, why not use
          web.config? You have the appSettings section as well as custom sections. And
          you
          can access your data via the ConfigurationMa nager class. So, no need to
          reinvent the wheel.
          -- Peter

          unBlog: http://petesbloggerama.blogspot.com
          BlogMetaFinder: http://www.blogmetafinder.com



          "shashwat_k11@y ahoo.com" wrote:
          Hi,
          >
          I am writing web service and I want to read a file only once when I
          start the web service. How can I do that? Which event fires exactly
          onece when we launch web service?
          >
          >
          >
          I am reading a xml file in the Init() so whenever the web service is
          invoked, it is reading that file. This is what I want to avoid. Where
          can I write the code so that the file gets read only once? Also where
          should I place the dll so that it will be accessible as long as the
          web service is running.
          >
          >

          Comment

          • jehugaleahsa@gmail.com

            #6
            Re: Web services start event and dll

            In the Start method of the Service class, simply read the file and
            then start the thread that does the work (you have to thread the main
            code in the service or your service will never get out of start mode.

            private System.Timers.T imer timer;

            public MyService()
            {
            // InitializeCompo nents();
            timer = new Timer(/* parameters for time interval */);
            timer.Elapsed += // method handler with method for executing main
            service code
            }

            // Changes status to running in service window while executing every
            interval
            public override void Start()
            {
            // Read file here
            timer.Enabled = true;
            }

            // Changes status to stop in service window
            public override void Stop()
            {
            // timer.Enabled = false;
            }

            Comment

            Working...