Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to use windows service in another project?

how to use windows service in another project?

Scheduled Pinned Locked Moved C#
questiondatabasehelptutorial
21 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Narendra Reddy Vajrala
    wrote on last edited by
    #1

    Hi Experts, i created a windows service to insert data in to a sql table. now i want to call this windows service in another project how can i call this? i tried to add service reference but it is asking for url how can i give this? like webservices, is windows services also contain URL? please help me out Thanks In Advance --Naren

    H V 2 Replies Last reply
    0
    • N Narendra Reddy Vajrala

      Hi Experts, i created a windows service to insert data in to a sql table. now i want to call this windows service in another project how can i call this? i tried to add service reference but it is asking for url how can i give this? like webservices, is windows services also contain URL? please help me out Thanks In Advance --Naren

      H Offline
      H Offline
      himanshu2561
      wrote on last edited by
      #2

      Hi, You can install the window service.It is not like webservices so it does not have any url.. Please read some stuff on google about window services.

      himanshu

      N 1 Reply Last reply
      0
      • H himanshu2561

        Hi, You can install the window service.It is not like webservices so it does not have any url.. Please read some stuff on google about window services.

        himanshu

        N Offline
        N Offline
        Narendra Reddy Vajrala
        wrote on last edited by
        #3

        Hi Himanshu, i installed my service, it is fine am performing start, stop, restart operations. but am stuck with calling this windows service in another project. :( i tried in google but i did not find any information reagrding this to call a windows service in another project.

        H 1 Reply Last reply
        0
        • N Narendra Reddy Vajrala

          Hi Himanshu, i installed my service, it is fine am performing start, stop, restart operations. but am stuck with calling this windows service in another project. :( i tried in google but i did not find any information reagrding this to call a windows service in another project.

          H Offline
          H Offline
          himanshu2561
          wrote on last edited by
          #4

          Hi You can not call window service in any project because it is not like class library. I am not getting what are you doing with window service. Please explain what is is currently doing and what are you planning to do?

          himanshu

          modified on Monday, June 29, 2009 8:28 AM

          N 1 Reply Last reply
          0
          • H himanshu2561

            Hi You can not call window service in any project because it is not like class library. I am not getting what are you doing with window service. Please explain what is is currently doing and what are you planning to do?

            himanshu

            modified on Monday, June 29, 2009 8:28 AM

            N Offline
            N Offline
            Narendra Reddy Vajrala
            wrote on last edited by
            #5

            what am trying to do is i want to insert records into a sqlTable for that i created a method with 4 arguments in windows services class. inside that method i wrote code to insert those 4 arguments. i installed this windows service. from another project i want to call this method To insert records from a form i called that service like this WindowsService1.Service1 winService = new WindowsService1.Service1(); winService.insertValues(txtcustId.Text, txtcustName.Text, txtcustPhone.Text, txtcustAddress.Text); here insertValues is my method inside windows service, where i wrote insert statement. is this correct way? when i tried to build it is giving below error Error 2 The type 'System.ServiceProcess.ServiceBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Inetpub\wwwroot\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 451 13 WindowsFormsApplication1

            modified on Monday, June 29, 2009 8:37 AM

            H 2 Replies Last reply
            0
            • N Narendra Reddy Vajrala

              what am trying to do is i want to insert records into a sqlTable for that i created a method with 4 arguments in windows services class. inside that method i wrote code to insert those 4 arguments. i installed this windows service. from another project i want to call this method To insert records from a form i called that service like this WindowsService1.Service1 winService = new WindowsService1.Service1(); winService.insertValues(txtcustId.Text, txtcustName.Text, txtcustPhone.Text, txtcustAddress.Text); here insertValues is my method inside windows service, where i wrote insert statement. is this correct way? when i tried to build it is giving below error Error 2 The type 'System.ServiceProcess.ServiceBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Inetpub\wwwroot\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 451 13 WindowsFormsApplication1

              modified on Monday, June 29, 2009 8:37 AM

              H Offline
              H Offline
              himanshu2561
              wrote on last edited by
              #6

              Hi, Stop your service from services.msc and check weather you are still able to insert records into your sql table. Just check it and you will find your answer :)

              himanshu

              N 1 Reply Last reply
              0
              • N Narendra Reddy Vajrala

                what am trying to do is i want to insert records into a sqlTable for that i created a method with 4 arguments in windows services class. inside that method i wrote code to insert those 4 arguments. i installed this windows service. from another project i want to call this method To insert records from a form i called that service like this WindowsService1.Service1 winService = new WindowsService1.Service1(); winService.insertValues(txtcustId.Text, txtcustName.Text, txtcustPhone.Text, txtcustAddress.Text); here insertValues is my method inside windows service, where i wrote insert statement. is this correct way? when i tried to build it is giving below error Error 2 The type 'System.ServiceProcess.ServiceBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\Inetpub\wwwroot\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 451 13 WindowsFormsApplication1

                modified on Monday, June 29, 2009 8:37 AM

                H Offline
                H Offline
                himanshu2561
                wrote on last edited by
                #7

                Hi if you want to achieve this type of functionality than i suggest you to consider webservice.Using window service you will not achieve this. Moreover,there is no point to keep busy your server by making window service.

                himanshu

                N 1 Reply Last reply
                0
                • H himanshu2561

                  Hi, Stop your service from services.msc and check weather you are still able to insert records into your sql table. Just check it and you will find your answer :)

                  himanshu

                  N Offline
                  N Offline
                  Narendra Reddy Vajrala
                  wrote on last edited by
                  #8

                  am giving my code sample protected override void OnStart(string[] args) { insertValues(3, "Naresh Kumar", "3658213641", "Begumpet Hyderabad"); } public void insertValues(int custId, string custName, string custPhone, string custAdd) { string insertCommand = "Insert into CUSTOMER values ( " + custId + ",'" + custName + "','" + custPhone + "','" + custAdd + "')"; con.Open(); cmd = new SqlCommand(insertCommand, con); cmd.ExecuteNonQuery(); con.Close(); } when am trying run this service from computer Mangement is it displaying below alert "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service." please help me out.

                  H 1 Reply Last reply
                  0
                  • H himanshu2561

                    Hi if you want to achieve this type of functionality than i suggest you to consider webservice.Using window service you will not achieve this. Moreover,there is no point to keep busy your server by making window service.

                    himanshu

                    N Offline
                    N Offline
                    Narendra Reddy Vajrala
                    wrote on last edited by
                    #9

                    ya actually but i have to do in windows services only. :(

                    J 1 Reply Last reply
                    0
                    • N Narendra Reddy Vajrala

                      ya actually but i have to do in windows services only. :(

                      J Offline
                      J Offline
                      J4amieC
                      wrote on last edited by
                      #10

                      Narendra Reddy Vajrala wrote:

                      actually but i have to do in windows services only

                      why? Says who?

                      N 1 Reply Last reply
                      0
                      • N Narendra Reddy Vajrala

                        am giving my code sample protected override void OnStart(string[] args) { insertValues(3, "Naresh Kumar", "3658213641", "Begumpet Hyderabad"); } public void insertValues(int custId, string custName, string custPhone, string custAdd) { string insertCommand = "Insert into CUSTOMER values ( " + custId + ",'" + custName + "','" + custPhone + "','" + custAdd + "')"; con.Open(); cmd = new SqlCommand(insertCommand, con); cmd.ExecuteNonQuery(); con.Close(); } when am trying run this service from computer Mangement is it displaying below alert "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service." please help me out.

                        H Offline
                        H Offline
                        himanshu2561
                        wrote on last edited by
                        #11

                        Narendra Reddy Vajrala wrote:

                        "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service.

                        This error means there is some error in the code of your window service. You have not done any exception handling.Write Try/Catch block to catch the exception and log that error in event viewer or log file.

                        himanshu

                        N 1 Reply Last reply
                        0
                        • J J4amieC

                          Narendra Reddy Vajrala wrote:

                          actually but i have to do in windows services only

                          why? Says who?

                          N Offline
                          N Offline
                          Narendra Reddy Vajrala
                          wrote on last edited by
                          #12

                          i cant break my PL orders :(

                          H J 2 Replies Last reply
                          0
                          • N Narendra Reddy Vajrala

                            Hi Experts, i created a windows service to insert data in to a sql table. now i want to call this windows service in another project how can i call this? i tried to add service reference but it is asking for url how can i give this? like webservices, is windows services also contain URL? please help me out Thanks In Advance --Naren

                            V Offline
                            V Offline
                            Vikram A Punathambekar
                            wrote on last edited by
                            #13

                            You are confusing web services and Windows services. I suggest you buy a book.

                            Cheers, Vikram.

                            Recent activities: TV series: Friends, season 9 Books: Freakonomics, by Steven Levitt and Stephen J Dubner.


                            Carpe Diem.

                            N 1 Reply Last reply
                            0
                            • N Narendra Reddy Vajrala

                              i cant break my PL orders :(

                              H Offline
                              H Offline
                              himanshu2561
                              wrote on last edited by
                              #14

                              who make him PL :confused:. Use web service..

                              himanshu

                              1 Reply Last reply
                              0
                              • H himanshu2561

                                Narendra Reddy Vajrala wrote:

                                "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service.

                                This error means there is some error in the code of your window service. You have not done any exception handling.Write Try/Catch block to catch the exception and log that error in event viewer or log file.

                                himanshu

                                N Offline
                                N Offline
                                Narendra Reddy Vajrala
                                wrote on last edited by
                                #15

                                same error no change :( even i used try catch block.

                                H 1 Reply Last reply
                                0
                                • V Vikram A Punathambekar

                                  You are confusing web services and Windows services. I suggest you buy a book.

                                  Cheers, Vikram.

                                  Recent activities: TV series: Friends, season 9 Books: Freakonomics, by Steven Levitt and Stephen J Dubner.


                                  Carpe Diem.

                                  N Offline
                                  N Offline
                                  Narendra Reddy Vajrala
                                  wrote on last edited by
                                  #16

                                  my code is like this in windows services class protected override void OnStart(string[] args) { insertValues(3, "Naresh Kumar", "3658213641", "Begumpet, Hyderabad"); } public void insertValues(int custId, string custName, string custPhone, string custAdd) { string insertCommand = "Insert into CUSTOMER values ( " + custId + ",'" + custName + "','" + custPhone + "','" + custAdd + "')"; con.Open(); cmd = new SqlCommand(insertCommand, con); cmd.ExecuteNonQuery(); con.Close(); } when am trying run this service from computer Mangement is it displaying below alert "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service." please help me out

                                  J 1 Reply Last reply
                                  0
                                  • N Narendra Reddy Vajrala

                                    same error no change :( even i used try catch block.

                                    H Offline
                                    H Offline
                                    himanshu2561
                                    wrote on last edited by
                                    #17

                                    Hi Have you log your error in log file or somewhere else... Read error from there and post it. Also, Do not use window service for this task.

                                    himanshu

                                    1 Reply Last reply
                                    0
                                    • N Narendra Reddy Vajrala

                                      my code is like this in windows services class protected override void OnStart(string[] args) { insertValues(3, "Naresh Kumar", "3658213641", "Begumpet, Hyderabad"); } public void insertValues(int custId, string custName, string custPhone, string custAdd) { string insertCommand = "Insert into CUSTOMER values ( " + custId + ",'" + custName + "','" + custPhone + "','" + custAdd + "')"; con.Open(); cmd = new SqlCommand(insertCommand, con); cmd.ExecuteNonQuery(); con.Close(); } when am trying run this service from computer Mangement is it displaying below alert "The service on local machine started and stopped. some services stopped automatically if they have no work to do for example the performance logs and alerts service." please help me out

                                      J Offline
                                      J Offline
                                      J4amieC
                                      wrote on last edited by
                                      #18

                                      The reason it stopped automatically is because there is no further work for the service to do once the line insertValue(...) has run. In general, windows services' OnStart method starts a thread/timer which continues to process until interupted by a Pause or Stop command. Whatever a "PL" is, he is an idiot, or you have misunderstood his request.

                                      1 Reply Last reply
                                      0
                                      • N Narendra Reddy Vajrala

                                        i cant break my PL orders :(

                                        J Offline
                                        J Offline
                                        J4amieC
                                        wrote on last edited by
                                        #19

                                        What is a "PL" and what specifically are their/it's "orders"?

                                        V 1 Reply Last reply
                                        0
                                        • J J4amieC

                                          What is a "PL" and what specifically are their/it's "orders"?

                                          V Offline
                                          V Offline
                                          Vikram A Punathambekar
                                          wrote on last edited by
                                          #20

                                          Project Lead, sounds like a cretin who's just been promoted into management by virtue of warming the seat for X years and is out to show his minions who's boss.

                                          Cheers, Vikram.

                                          Recent activities: TV series: Friends, season 9 Books: Freakonomics, by Steven Levitt and Stephen J Dubner.


                                          Carpe Diem.

                                          J 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups