views:

111

answers:

2

Hi guys

We've written a Windows Service that needs to send an HTTP request in order to post some xml data to another server. When we test the code via a console application, it works fine, but when we test it by running it as a service, it errors on this line of code:

var httpWebRequest = (HttpWebRequest)WebRequest.Create(Uri);

The error message is:

"Configuration system failed to initialize"

We're thinking the error is due to the User Account under which the Windows Service is running not having the permissions to make HTTP requests, we've tried running it under the local administrator account, but to no avail. It's not a question of supplying a username and password because when we run the code as a Console Application, the above line of code executes fine.

Any suggestions greatly appreciated! Many thanks.

A: 

It's unlikely to be a security problem.

Judging by posts like this one:

http://blogs.msdn.com/jongallant/archive/2008/03/02/configuration-system-failed-to-initialize-one-possible-solution.aspx it seems to come from a configuration file problem. I guess "Uri" is some property that gets initialized by looking at a config file.

The problem here may come from either a non conformant config file, or from the service loading a config file from some strange place (since it's running as a service). You may want to look at procmon from sysinternals to see what your service is loading when starting up.

Yann Schwartz
Thanks Yann, but the Uri is a hard coded string that is not being read from any config file, so there are no config file issues here.
FreeFalling
Can you provide the full stacktrace of the exception ?
Yann Schwartz
System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName) at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName) at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
FreeFalling
at System.Diagnostics.DiagnosticsConfiguration.Initialize() at System.Diagnostics.DiagnosticsConfiguration.get_Sources() at System.Diagnostics.TraceSource.Initialize() at System.Net.Logging.InitializeLogging() at System.Net.Logging.get_On() at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase) at System.Net.WebRequest.Create(String requestUriString)
FreeFalling
at Logic.API.Parsers.Communicator.GetResponse(String xml) in C:\EPiServer\Sites\CompanyX\CompanyX.BL\Logic\API\Parsers\Communicator.cs:line 168 at Logic.Factory.GetVoyagesByShip(String shipCode, String fileloc) in C:\EPiServer\Sites\CompanyX\CompanyX.BL\Logic\VoyageFactory.cs:line 101 at BookingEngineCacheService.Cacher.Cache() in C:\EPiServer\Sites\CompanyX\CompanyX.BL\BookingEngineCacheService\Cacher.cs:line 126
FreeFalling
A: 

Do you have user-scoped settings? There isn't any user profile loaded for windows service (that is, until you load one by yourself) so user-scoped setting would be missing.

Sheng Jiang 蒋晟
Have solved the problem. There was a problem with the machine.config file in the <system.serviceModel> node there were some settings misconfigured. Got another machine.config file from another PC, and it's working fine now. Thanks to those that tried to help.
FreeFalling