By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Problem with self hosting under the NetworkService account

P: n/a
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
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>
Nov 4 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Dave,

From your description, your windows service hosted WCF service report
exception at startup time, correct?

According to the error message and code snippet you provided, I think the
code and configuration should be ok. And since changing account will make
the result different, the problem is likely to be a permission specific
issue.

So far, based on my experience, there is a potential issue(which might be
caused by unsufficient permission) when initilaize the WCF host. That's the
registring of the http listening url on vista machine. Based on the
computer name and wcf configuration, I think your dev box is a vista box
and you're using http channel, therefore, I think it is likely the cause.

Here is a web article which mentioned detailed information on registering
http url on vista machine(for a certain user account). You can try granting
the http url (You want to use for your WCF endpoint) access permission to
the service account:

#AddressAccessDeniedException: HTTP could not register URL
http://+:8080/<*>.
http://blogs.msdn.com/paulwh/archive...eniedexception
-http-could-not-register-url-http-8080.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from

the community or a Microsoft Support Engineer within 2 business day is
acceptable. Please note that

each follow up response may take approximately 2 business days as the
support professional working

with you may need further investigation to reach the most efficient
resolution. The offering is not

appropriate for situations that require urgent, real-time or phone-based
interactions. Issues of this

nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft

Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
From: "Dave Burns" <db****@newsgroup.nospam>
Subject: Problem with self hosting under the NetworkService account
Date: Tue, 4 Nov 2008 12:53:41 -0600

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
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>

Nov 5 '08 #2

P: n/a
I see this problem on XP as well. On Vista I run as an Administrator, on XP
as well during the install of the service.

Also, I am not getting an AddressAccessDeniedException, I am getting an
NullReferenceException.

Any other ideas?

Thanks, Dave
""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:R8*************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

From your description, your windows service hosted WCF service report
exception at startup time, correct?

According to the error message and code snippet you provided, I think the
code and configuration should be ok. And since changing account will make
the result different, the problem is likely to be a permission specific
issue.

So far, based on my experience, there is a potential issue(which might be
caused by unsufficient permission) when initilaize the WCF host. That's
the
registring of the http listening url on vista machine. Based on the
computer name and wcf configuration, I think your dev box is a vista box
and you're using http channel, therefore, I think it is likely the cause.

Here is a web article which mentioned detailed information on registering
http url on vista machine(for a certain user account). You can try
granting
the http url (You want to use for your WCF endpoint) access permission to
the service account:

#AddressAccessDeniedException: HTTP could not register URL
http://+:8080/<*>.
http://blogs.msdn.com/paulwh/archive...eniedexception
-http-could-not-register-url-http-8080.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my
manager
at: ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from

the community or a Microsoft Support Engineer within 2 business day is
acceptable. Please note that

each follow up response may take approximately 2 business days as the
support professional working

with you may need further investigation to reach the most efficient
resolution. The offering is not

appropriate for situations that require urgent, real-time or phone-based
interactions. Issues of this

nature are best handled working with a dedicated Microsoft Support
Engineer
by contacting Microsoft

Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.


--------------------
From: "Dave Burns" <db****@newsgroup.nospam>
Subject: Problem with self hosting under the NetworkService account
Date: Tue, 4 Nov 2008 12:53:41 -0600

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
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>

Nov 5 '08 #3

P: n/a
Thanks for your reply Dave,

Yes, the problem I refered is due to access permission while the problem
you encounter report a "Null Reference" error directly. Currently, I'm
thinking two means to further troubleshoot the issue:

1. I'm wondering whether it's the http endpoint channel that cause the
issue. I suggest you try configuring the WCF service via Tcp channel to see
whether the same problem occurs. If the problem doesn't occur for TCP
channel, that means there is still something wrong with the HTTP url
registering.

2. If you can also repro the problem on non-vista box, would you try
creating a simplified repro solution with a simple WCF service that can
repro the same behavior. thus, I can try performing some test on my side.
We may need to use debugger to have alook at the detailed exception info.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: ms****@microsoft.com.

--------------------
From: "Dave Burns" <db****@newsgroup.nospam>
References: <uJ**************@TK2MSFTNGP03.phx.gbl>
<R8*************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Problem with self hosting under the NetworkService account
Date: Wed, 5 Nov 2008 11:01:34 -0600

I see this problem on XP as well. On Vista I run as an Administrator, on XP
as well during the install of the service.

Also, I am not getting an AddressAccessDeniedException, I am getting an
NullReferenceException.

Any other ideas?

Thanks, Dave
""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:R8*************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

From your description, your windows service hosted WCF service report
exception at startup time, correct?

According to the error message and code snippet you provided, I think the
code and configuration should be ok. And since changing account will make
the result different, the problem is likely to be a permission specific
issue.

So far, based on my experience, there is a potential issue(which might be
caused by unsufficient permission) when initilaize the WCF host. That's
the
registring of the http listening url on vista machine. Based on the
computer name and wcf configuration, I think your dev box is a vista box
and you're using http channel, therefore, I think it is likely the cause.

Here is a web article which mentioned detailed information on registering
http url on vista machine(for a certain user account). You can try
granting
the http url (You want to use for your WCF endpoint) access permission to
the service account:

#AddressAccessDeniedException: HTTP could not register URL
http://+:8080/<*>.
http://blogs.msdn.com/paulwh/archive...eniedexception
-http-could-not-register-url-http-8080.aspx

Sincerely,
Nov 6 '08 #4

P: n/a
Hi Dave,

Have you got any progress on this issue or have any new findings on this
issue?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we

can improve the support we provide to you. Please feel free to let my
manager know what you think of

the level of service provided. You can send feedback directly to my manager
at: ms****@microsoft.com.
--------------------
From: st*****@online.microsoft.com ("Steven Cheng")
Organization: Microsoft
Date: Thu, 06 Nov 2008 06:16:45 GMT
Subject: Re: Problem with self hosting under the NetworkService account
Thanks for your reply Dave,

Yes, the problem I refered is due to access permission while the problem
you encounter report a "Null Reference" error directly. Currently, I'm
thinking two means to further troubleshoot the issue:

1. I'm wondering whether it's the http endpoint channel that cause the
issue. I suggest you try configuring the WCF service via Tcp channel to see
whether the same problem occurs. If the problem doesn't occur for TCP
channel, that means there is still something wrong with the HTTP url
registering.

2. If you can also repro the problem on non-vista box, would you try
creating a simplified repro solution with a simple WCF service that can
repro the same behavior. thus, I can try performing some test on my side.
We may need to use debugger to have alook at the detailed exception info.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

--------------------
From: "Dave Burns" <db****@newsgroup.nospam>
References: <uJ**************@TK2MSFTNGP03.phx.gbl>
<R8*************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Problem with self hosting under the NetworkService account
Date: Wed, 5 Nov 2008 11:01:34 -0600

I see this problem on XP as well. On Vista I run as an Administrator, on XP
as well during the install of the service.

Also, I am not getting an AddressAccessDeniedException, I am getting an
NullReferenceException.

Any other ideas?

Thanks, Dave
""Steven Cheng"" <st*****@online.microsoft.comwrote in message
news:R8*************@TK2MSFTNGHUB02.phx.gbl...
Hi Dave,

From your description, your windows service hosted WCF service report
exception at startup time, correct?

According to the error message and code snippet you provided, I think the
code and configuration should be ok. And since changing account will make
the result different, the problem is likely to be a permission specific
issue.

So far, based on my experience, there is a potential issue(which might be
caused by unsufficient permission) when initilaize the WCF host. That's
the
registring of the http listening url on vista machine. Based on the
computer name and wcf configuration, I think your dev box is a vista box
and you're using http channel, therefore, I think it is likely the cause.

Here is a web article which mentioned detailed information on registering
http url on vista machine(for a certain user account). You can try
granting
the http url (You want to use for your WCF endpoint) access permission to
the service account:

#AddressAccessDeniedException: HTTP could not register URL
http://+:8080/<*>.
http://blogs.msdn.com/paulwh/archive...eniedexception
-http-could-not-register-url-http-8080.aspx

Sincerely,

Nov 11 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.