PC Review


Reply
Thread Tools Rate Thread

How to debug a service ?

 
 
cyshao
Guest
Posts: n/a
 
      24th Mar 2005
How to debug a service ?

Hi, friends:

I created a new C# service project and wrote some log in OnStart()
function.
But when I type F5 to debug it, system prompt me
"Can't debug a service program by debugger. Please use installutil.exe
to install it."

So, I tried to use " installutil MyPorgram.exe". But there is an error
written in logfile.
I don't know what does "public installers " mean ? What shall I do to
solve that?

Thanks

Charles Shao :-)

------------------------------Log File -----------------------------------

No public installers with the RunInstallerAttribute.Yes attribute could be
found in the
d:\project\directoryservices\directoryservices\agent\bin\deubgunittests\asti
..bos.directoryservices.agent.exe assembly.
Remove InstallState file because there are no installers.



 
Reply With Quote
 
 
 
 
Adrian
Guest
Posts: n/a
 
      24th Mar 2005
Use the code below in a new .cs file and then use installutil.

using System;
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
[RunInstallerAttribute(true)]
public class ProjectInstaller: Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public ProjectInstaller()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
// Service will run under system account
processInstaller.Account = ServiceAccount.LocalSystem;
// Service will have Start Type of Manual
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "svchost";
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}

Best regards.


 
Reply With Quote
 
Adrian
Guest
Posts: n/a
 
      24th Mar 2005
Change "svchost" with an appropiate name ServiceName.


 
Reply With Quote
 
Hans Kesting
Guest
Posts: n/a
 
      24th Mar 2005
cyshao wrote:
> How to debug a service ?
>
> Hi, friends:
>
> I created a new C# service project and wrote some log in OnStart()
> function.
> But when I type F5 to debug it, system prompt me
> "Can't debug a service program by debugger. Please use installutil.exe
> to install it."
>
> So, I tried to use " installutil MyPorgram.exe". But there is an error
> written in logfile.
> I don't know what does "public installers " mean ? What shall I do to
> solve that?
>
> Thanks
>
> Charles Shao :-)
>
> ------------------------------Log File -----------------------------------
>
> No public installers with the RunInstallerAttribute.Yes attribute could be
> found in the
> d:\project\directoryservices\directoryservices\agent\bin\deubgunittests\asti
> .bos.directoryservices.agent.exe assembly.
> Remove InstallState file because there are no installers.
>
>
>


1) when you run InstallUtil it will search for a class that is marked
with the [RunInstaller(true)] attribute. This will do the actual
installing. It needs to derive from
System.Configuration.Install.Installer. I believe MSDN has
examples on how you can make this class.

2) for debugging: I don't think you can debug a service. What you
*can* do however: put all the logic into a different project
and have a third project with a winform project, where you can call
the various "worker methods" from the logic-project.
The "service" project has only the basic service-hooks.

--
Hans Kesting
 
Reply With Quote
 
Adrian
Guest
Posts: n/a
 
      24th Mar 2005
To debag a service, you could try this:
comment the line with

System.ServiceProcess.ServiceBase.Run(new Service1());

Then add

Service1 s = new Service1();
s.Method1();
....
....

The project will be transformed in a console application.

Hope that helps.


 
Reply With Quote
 
Dale Preston
Guest
Posts: n/a
 
      25th Mar 2005
To debug a service, after all the things already discussed have been done to
get your service installed, open the service project and open a client or
service consumer project. Attach the debugger to the consumer project and
set a break point in your service.

HTH

Dale Preston
MCAD, MCDBA, MCSE

"cyshao" <(E-Mail Removed)> wrote in message
news:uR#(E-Mail Removed)...
> How to debug a service ?
>
> Hi, friends:
>
> I created a new C# service project and wrote some log in OnStart()
> function.
> But when I type F5 to debug it, system prompt me
> "Can't debug a service program by debugger. Please use

installutil.exe
> to install it."
>
> So, I tried to use " installutil MyPorgram.exe". But there is an error
> written in logfile.
> I don't know what does "public installers " mean ? What shall I do to
> solve that?
>
> Thanks
>
> Charles Shao :-)
>
> ------------------------------Log File -----------------------------------
>
> No public installers with the RunInstallerAttribute.Yes attribute could be
> found in the
>

d:\project\directoryservices\directoryservices\agent\bin\deubgunittests\asti
> .bos.directoryservices.agent.exe assembly.
> Remove InstallState file because there are no installers.
>
>
>



 
Reply With Quote
 
cyshao
Guest
Posts: n/a
 
      1st Apr 2005
ho. It's a good idea^o^

"Adrian" <(E-Mail Removed)> дÈëÓʼþ
news:(E-Mail Removed)...
> To debag a service, you could try this:
> comment the line with
>
> System.ServiceProcess.ServiceBase.Run(new Service1());
>
> Then add
>
> Service1 s = new Service1();
> s.Method1();
> ...
> ...
>
> The project will be transformed in a console application.
>
> Hope that helps.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to debug a web service steven Microsoft Dot NET 2 1st Dec 2007 12:35 AM
Debug Web service Harry Simpson Microsoft Dot NET Compact Framework 3 31st Aug 2007 06:40 PM
V Studio 2003 Doesn't Load Supporting DLL Debug Symbols for Windows Service Remote Debug INGSOC Microsoft C# .NET 0 8th Feb 2005 09:19 AM
debug web service keith Microsoft Dot NET 0 19th Oct 2003 04:18 AM
How to: Debug Windows Service alien2_51 Microsoft Dot NET Framework 1 10th Oct 2003 09:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.