I am self hosting a Web Service in a Windows service. I am trying to start
the service using the NT AUTHORITY\NetworkService account.
I get a NullReferenceException on ServiceHost.Open() in the
ServiceBase.OnStart() method. SCM throws a 1067 error as well.
I get the same problem with NT AUTHORITY\LocalService.
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 Raskin
Here's the code snippet:
class HostService : ServiceBase
{
private EventLog log;
private ServiceHost testServiceHost;
public HostService()
{
CanPauseAndContinue = false;
ServiceName = "Test Web Service";
// create an EventLog instance and assign its source.
this.log = new EventLog();
this.log.Source = HostInstaller.SERVICE_EVENT_SOURCE;
EventLog.WriteEntry("Got through constructor",
EventLogEntryType.Information);
}
static void Main()
{
// load the service into memory.
ServiceBase.Run(new HostService());
}
// start the service.
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("At the top of OnStart",
EventLogEntryType.Information);
// request 60 seconds for startup from SCM, just in case
RequestAdditionalTime(60000);
EventLog.WriteEntry("After RequestAdditionalTime()",
EventLogEntryType.Information);
// start self hosting
ServiceEndpoint endpoint = null;
try
{
endpoint = this.testServiceHost.Description.Endpoints[0];
this.testServiceHost = new ServiceHost(typeof(RmTestService));
EventLog.WriteEntry("After new ServiceHost()",
EventLogEntryType.Information);
// blows up here!!!
this.testServiceHost.Open();
}
catch (Exception e)
{
EventLog.WriteEntry("Problem starting " + endpoint.Contract.Name
+ ": " + e.Message, EventLogEntryType.Error);
throw e;
}
}
Here's app.config snippet:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="RmWebService.RmWebServiceBe havior"
name="Rimage.Web.Service.RmTestService">
<host>
<baseAddresses>
<add
baseAddress="http://vista-draskin:55555/RmTestService.svc"/>
</baseAddresses>
</host>
<endpoint address="http://vista-draskin:55555/RmTestService.svc"
binding="basicHttpBinding" name="SoapEndpoint"
bindingNamespace="http://www.rimage.com/RmTestService"
contract="Rimage.Web.Service.IRmTestService"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" name="MexEndpoint"
bindingNamespace="http://www.rimage.com/RmTestService"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior
name="Rimage.Web.Service.RmAjaxTestServiceAspNetAj axBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="RmWebService.RmWebServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>