0
我收到以下錯誤從Windows服務應用Windows服務創建Web客戶端請求
System.Net.WebException = {"An exception occurred during a WebClient request."}
-2146233079
InnerException = {"Configuration system failed to initialize"}
上的控制檯應用程序相同的代碼工作正常時出現的異常。
服務文件並沒有對「本地服務」(在我的測試環境)設置安全
你能指出我什麼可能導致錯誤,以及如何解決呢?
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
我的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>