Problem with self hosting under the NetworkService account

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Burns

    #1

    Problem with self hosting under the NetworkService account

    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>


  • Steven Cheng

    #2
    RE: Problem with self hosting under the NetworkService account

    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:

    #AddressAccessD eniedException: 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: msdnmg@microsof t.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" <dburns@newsgro up.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\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

    • Dave Burns

      #3
      Re: Problem with self hosting under the NetworkService account

      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 AddressAccessDe niedException, I am getting an
      NullReferenceEx ception.

      Any other ideas?

      Thanks, Dave


      ""Steven Cheng"" <stcheng@online .microsoft.comw rote in message
      news:R8AgTjvPJH A.312@TK2MSFTNG HUB02.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:
      >
      #AddressAccessD eniedException: 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: msdnmg@microsof t.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" <dburns@newsgro up.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\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

      • Steven Cheng

        #4
        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: msdnmg@microsof t.com.

        --------------------
        From: "Dave Burns" <dburns@newsgro up.nospam>
        References: <uJXqQ7qPJHA.49 08@TK2MSFTNGP03 .phx.gbl>
        <R8AgTjvPJHA.31 2@TK2MSFTNGHUB0 2.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 AddressAccessDe niedException, I am getting an
        NullReferenceEx ception.

        Any other ideas?

        Thanks, Dave


        ""Steven Cheng"" <stcheng@online .microsoft.comw rote in message
        news:R8AgTjvPJH A.312@TK2MSFTNG HUB02.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:
        >
        #AddressAccessD eniedException: HTTP could not register URL
        http://+:8080/<¡­>.
        >
        http://blogs.msdn.com/paulwh/archive...eniedexception
        -http-could-not-register-url-http-8080.aspx
        >
        Sincerely,

        Comment

        • Steven Cheng

          #5
          Re: Problem with self hosting under the NetworkService account

          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: msdnmg@microsof t.com.
          --------------------
          From: stcheng@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:
          msdnmg@microsof t.com.

          --------------------
          From: "Dave Burns" <dburns@newsgro up.nospam>
          References: <uJXqQ7qPJHA.49 08@TK2MSFTNGP03 .phx.gbl>
          <R8AgTjvPJHA.31 2@TK2MSFTNGHUB0 2.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 AddressAccessDe niedException, I am getting an
          NullReferenceEx ception.

          Any other ideas?

          Thanks, Dave


          ""Steven Cheng"" <stcheng@online .microsoft.comw rote in message
          news:R8AgTjvPJH A.312@TK2MSFTNG HUB02.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:
          >
          #AddressAccessD eniedException: HTTP could not register URL
          http://+:8080/<¡­>.
          >
          http://blogs.msdn.com/paulwh/archive...eniedexception
          -http-could-not-register-url-http-8080.aspx
          >
          Sincerely,

          Comment

          Working...