我们编写了一个Windows服务,需要发送HTTP请求才能将一些xml数据发布到另一台服务器。当我们通过一个控制台应用程序测试代码,它工作正常,但是当我们运行它作为一种服务,它在这行代码中的错误进行测试:Windows服务中的HTTP请求问题
var httpWebRequest = (HttpWebRequest)WebRequest.Create(Uri);
的错误信息是:
"Configuration system failed to initialize"
我们认为这个错误是由于Windows服务运行时没有权限发出HTTP请求的用户帐户造成的,我们尝试在本地管理员帐户下运行它,但无济于事。这不是提供用户名和密码的问题,因为当我们将代码作为控制台应用程序运行时,上面的代码行执行得很好。
任何建议,不胜感激!非常感谢。
感谢Yann,但Uri是一个硬编码的字符串,它不会从任何配置文件读取,因此这里没有配置文件问题。 – FreeFalling 2009-10-28 11:33:13
你能提供异常的完整堆栈跟踪吗? – 2009-10-28 12:31:02
System.Configuration.ClientConfigurationSystem.EnsureInit(字符串configKey) 在System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(字符串sectionName) 在System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(字符串sectionName) 在系统。 Configuration.ConfigurationManager.GetSection(字符串sectionName) 在System.Configuration.PrivilegedConfigurationManager.GetSection(字符串sectionName) 在System.Diagnostics.DiagnosticsConfiguration.GetConfigSection() – FreeFalling 2009-10-28 14:48:18