I am self hosting a Web Service in a Windows service. I am trying to start
the service using the NT AUTHORITY\Netwo rkService account.
I get a NullReferenceEx ception on ServiceHost.Ope n() in the
ServiceBase.OnS tart() method. SCM throws a 1067 error as well.
I get the same problem with NT AUTHORITY\Local Service.
When I use the LocalSystem account, my domain account, or another regular
user account, the windows service starts just fine.
I would appreciate any help on this topic, thanks in advance!
Dave
Here's the code snippet:
class HostService : ServiceBase
{
private EventLog log;
private ServiceHost testServiceHost ;
public HostService()
{
CanPauseAndCont inue = false;
ServiceName = "Test Web Service";
// create an EventLog instance and assign its source.
this.log = new EventLog();
this.log.Source = HostInstaller.S ERVICE_EVENT_SO URCE;
EventLog.WriteE ntry("Got through constructor",
EventLogEntryTy pe.Information) ;
}
static void Main()
{
// load the service into memory.
ServiceBase.Run (new HostService());
}
// start the service.
protected override void OnStart(string[] args)
{
EventLog.WriteE ntry("At the top of OnStart",
EventLogEntryTy pe.Information) ;
// request 60 seconds for startup from SCM, just in case
RequestAddition alTime(60000);
EventLog.WriteE ntry("After RequestAddition alTime()",
EventLogEntryTy pe.Information) ;
// start self hosting
ServiceEndpoint endpoint = null;
try
{
endpoint = this.testServic eHost.Descripti on.Endpoints[0];
this.testServic eHost = new ServiceHost(typ eof(RmTestServi ce));
EventLog.WriteE ntry("After new ServiceHost()",
EventLogEntryTy pe.Information) ;
// blows up here!!!
this.testServic eHost.Open();
}
catch (Exception e)
{
EventLog.WriteE ntry("Problem starting " + endpoint.Contra ct.Name
+ ": " + e.Message, EventLogEntryTy pe.Error);
throw e;
}
}
Here's app.config snippet:
<system.service Model>
<serviceHosting Environment aspNetCompatibi lityEnabled="tr ue" />
<services>
<service behaviorConfigu ration="RmWebSe rvice.RmWebServ iceBehavior"
name="Rimage.We b.Service.RmTes tService">
<host>
<baseAddresse s>
<add
baseAddress="ht tp://vista-draskin:55555/RmTestService.s vc"/>
</baseAddresses>
</host>
<endpoint address="http://vista-draskin:55555/RmTestService.s vc"
binding="basicH ttpBinding" name="SoapEndpo int"
bindingNamespac e="http://www.rimage.com/RmTestService"
contract="Rimag e.Web.Service.I RmTestService"
listenUriMode=" Explicit">
<identity>
<dns value="localhos t" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHtt pBinding" name="MexEndpoi nt"
bindingNamespac e="http://www.rimage.com/RmTestService"
contract="IMeta dataExchange" />
</service>
</services>
<behaviors>
<endpointBehavi ors>
<behavior
name="Rimage.We b.Service.RmAja xTestServiceAsp NetAjaxBehavior ">
<enableWebScrip t />
</behavior>
</endpointBehavio rs>
<serviceBehavio rs>
<behavior name="RmWebServ ice.RmWebServic eBehavior">
<serviceMetadat a httpGetEnabled= "true" />
<serviceDebug includeExceptio nDetailInFaults ="true" />
</behavior>
</serviceBehavior s>
</behaviors>
</system.serviceM odel>
the service using the NT AUTHORITY\Netwo rkService account.
I get a NullReferenceEx ception on ServiceHost.Ope n() in the
ServiceBase.OnS tart() method. SCM throws a 1067 error as well.
I get the same problem with NT AUTHORITY\Local Service.
When I use the LocalSystem account, my domain account, or another regular
user account, the windows service starts just fine.
I would appreciate any help on this topic, thanks in advance!
Dave
Here's the code snippet:
class HostService : ServiceBase
{
private EventLog log;
private ServiceHost testServiceHost ;
public HostService()
{
CanPauseAndCont inue = false;
ServiceName = "Test Web Service";
// create an EventLog instance and assign its source.
this.log = new EventLog();
this.log.Source = HostInstaller.S ERVICE_EVENT_SO URCE;
EventLog.WriteE ntry("Got through constructor",
EventLogEntryTy pe.Information) ;
}
static void Main()
{
// load the service into memory.
ServiceBase.Run (new HostService());
}
// start the service.
protected override void OnStart(string[] args)
{
EventLog.WriteE ntry("At the top of OnStart",
EventLogEntryTy pe.Information) ;
// request 60 seconds for startup from SCM, just in case
RequestAddition alTime(60000);
EventLog.WriteE ntry("After RequestAddition alTime()",
EventLogEntryTy pe.Information) ;
// start self hosting
ServiceEndpoint endpoint = null;
try
{
endpoint = this.testServic eHost.Descripti on.Endpoints[0];
this.testServic eHost = new ServiceHost(typ eof(RmTestServi ce));
EventLog.WriteE ntry("After new ServiceHost()",
EventLogEntryTy pe.Information) ;
// blows up here!!!
this.testServic eHost.Open();
}
catch (Exception e)
{
EventLog.WriteE ntry("Problem starting " + endpoint.Contra ct.Name
+ ": " + e.Message, EventLogEntryTy pe.Error);
throw e;
}
}
Here's app.config snippet:
<system.service Model>
<serviceHosting Environment aspNetCompatibi lityEnabled="tr ue" />
<services>
<service behaviorConfigu ration="RmWebSe rvice.RmWebServ iceBehavior"
name="Rimage.We b.Service.RmTes tService">
<host>
<baseAddresse s>
<add
baseAddress="ht tp://vista-draskin:55555/RmTestService.s vc"/>
</baseAddresses>
</host>
<endpoint address="http://vista-draskin:55555/RmTestService.s vc"
binding="basicH ttpBinding" name="SoapEndpo int"
bindingNamespac e="http://www.rimage.com/RmTestService"
contract="Rimag e.Web.Service.I RmTestService"
listenUriMode=" Explicit">
<identity>
<dns value="localhos t" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHtt pBinding" name="MexEndpoi nt"
bindingNamespac e="http://www.rimage.com/RmTestService"
contract="IMeta dataExchange" />
</service>
</services>
<behaviors>
<endpointBehavi ors>
<behavior
name="Rimage.We b.Service.RmAja xTestServiceAsp NetAjaxBehavior ">
<enableWebScrip t />
</behavior>
</endpointBehavio rs>
<serviceBehavio rs>
<behavior name="RmWebServ ice.RmWebServic eBehavior">
<serviceMetadat a httpGetEnabled= "true" />
<serviceDebug includeExceptio nDetailInFaults ="true" />
</behavior>
</serviceBehavior s>
</behaviors>
</system.serviceM odel>
Comment