简体   繁体   English

Windows服务WebClient请求期间发生异常

[英]Windows Service An exception occurred during a WebClient request

I receive the following error from a Windows Service application 我从Windows服务应用程序收到以下错误

   System.Net.WebException = {"An exception occurred during a WebClient request."}
    -2146233079
    InnerException = {"Configuration system failed to initialize"}

The same code on a Console application works fine. 控制台应用程序上的相同代码可以正常工作。

The Service file has not setup Security on "Local Service" (in my test environment) 服务文件尚未在“本地服务”上设置安全性(在我的测试环境中)

Could you point me out what could cause the error and how to solve it? 您能否指出我可能导致该错误的原因以及如何解决该错误?

    Try
        Using client As New Net.WebClient
            Dim reqparm As New Specialized.NameValueCollection
            reqparm.Add("DeviceId", deviceId)
            reqparm.Add("StatusCode", statusCode)
            reqparm.Add("Type", "printer")
            reqparm.Add("Message", msg)
            Dim responsebytes = client.UploadValues("http://xxx.xxx.com/api/notification", "POST", reqparm)
            Dim responsebody = (New Text.UTF8Encoding).GetString(responsebytes)
        End Using
    Catch ex As Exception
        'do nothing
    End Try

my App.config 我的App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <configSections>
    <section name="app" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <app>
    <add key="version" value="0.0.1"/>
  </app>
</configuration>

The problem was in the App.config file. 问题出在App.config文件中。 This the correct version, only one instance of <configSections> and should be the first element after <configuration> . 这是正确的版本,只有<configSections>一个实例,并且应该是<configuration>之后的第一个元素。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="app" type="System.Configuration.NameValueSectionHandler" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <app>
    <add key="version" value="0.0.1"/>
  </app>
</configuration>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebClient请求期间发生异常 - Exception occurred during a WebClient request WebClient请求期间发生异常。 在Windows Phone中 - An exception occurred during a WebClient request. in windows phone 使用任务计划程序时“WebClient 请求期间发生异常” - "An exception occurred during a WebClient request" when using the Task Scheduler 使用webclient下载大文件时出现“ WebClient请求期间发生异常” - Getting “An exception occurred during a WebClient request” while download the large file using webclient 为什么从网站下载图像时出现异常:WebClient请求期间发生异常? - Why when downloading images from a website im getting exception: An exception occurred during a WebClient request? 使用C#ASP.NET时,“WebClient请求期间发生异常” - 'An exception occurred during a WebClient request" while using C# ASP.NET 当前Web请求“Ненайденуказанныймодуль”的执行期间发生未处理的异常 - An unhandled exception occurred during the execution of the current web request, “Не найден указанный модуль” 当前Web请求执行期间发生未处理的异常 - An unhandled exception occurred during the execution of the current web request 在为该请求提供服务所需的资源的编译过程中发生错误4 - An error occurred during the compilation of a resource required to service this request4 编译服务此请求所需的资源期间发生错误 - An error occurred during the compilation of a resource required to service this request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM