简体   繁体   English

在调试器中运行的应用程序连接到Web服务,但作为Windows Service运行时不连接

[英]Application running in debugger connects to webservice in but not when running as windows service

I've created an application in C# which I run as a Windows Service. 我已经在C#中创建了一个作为Windows服务运行的应用程序。 This works fine. 这很好。

I've recently modified it so that it connects to a Web Service. 我最近对其进行了修改,使其可以连接到Web服务。 When running in Studio, this new code works fine and connects to the Web Service. 在Studio中运行时,此新代码可以正常工作并连接到Web服务。 However when I run the program as a Windows Service (on the same machine) the program times out as it cannot connect to the Web Service (gives the exception - unable to connect to the remote server). 但是,当我以Windows服务(在同一台计算机上)运行该程序时,该程序超时,因为它无法连接到Web服务(给出例外-无法连接到远程服务器)。

Can anyone think why this might be happening? 谁能想到为什么会这样?

The exception seen when run as a service is: 作为服务运行时看到的异常是:

System.Net.WebException was unhandled
Message="Unable to connect to the remote server"
Source="System"
StackTrace:
   at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
   at System.Net.HttpWebRequest.GetRequestStream()
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,          Object[] parameters)
   at DataExtractionService.uk.co.myserver.Service1.SendEmail(String Message, String Subject, String FromAddress, String[] ToAddress, String[] AttachmentNames, Object[] AttachmentData) in C:\Documents and Settings\administrator.MLR\My Documents\Visual Studio 2005\Projects\DataExtractionService\DataExtractionService\Web References\uk.co.myserver\Reference.cs:line 111
   at DataExtractionService.APDataExtractor.EmailReport(String message, String subject) in C:\Documents and Settings\administrator.MLR\My Documents\Visual Studio 2005\Projects\DataExtractionService\DataExtractionService\APDataExtractor.cs:line 610
   at DataExtractionService.APDataExtractor.RunDataExtraction() in C:\Documents and Settings\administrator.MLR\My Documents\Visual Studio 2005\Projects\DataExtractionService\DataExtractionService\APDataExtractor.cs:line 63
   at DataExtractionService.DataExtractionService.HandleClientComm(Object client) in C:\Documents and Settings\administrator.MLR\My Documents\Visual Studio 2005\Projects\DataExtractionService\DataExtractionService\DataExtractionService.cs:line 96
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)

The webservice was just added to the project in the normal way under 'Web References'. 只是以常规方式将Web服务添加到了“ Web参考”下的项目中。 The webservice works correctly in Studio. 该Web服务在Studio中可以正常工作。

The relevant part of the exe.config is shown below (I've had to change the name of the server, sorry): exe.config的相关部分如下所示(抱歉,我不得不更改服务器的名称):

<applicationSettings>
<DataExtractionService.Properties.Settings>
  <setting name="DataExtractionService_uk_co_myserver_Service1"
    serializeAs="String">
    <value>https://myserver.co.uk/premieremailservice/Service1.asmx</value>
  </setting>
</DataExtractionService.Properties.Settings>
 </applicationSettings>

Many thanks. 非常感谢。

Where is the web service running? Web服务在哪里运行? What type of authentication (if any) does it require? 它需要什么类型的身份验证(如果有)? If your Windows service is running under a local account (such as System or Network Service) then it may not have the necessary permissions to connect to something remote. 如果您的Windows服务在本地帐户(例如“系统”或“网络服务”)下运行,则它可能没有连接到远程对象的必要权限。

If this is the case then you need to execute the windows service under a domain account and give that account permissions to talk to the web service, or remove authentication altogether. 如果是这种情况,则需要在域帐户下执行Windows服务,并授予该帐户与Web服务对话的权限,或者完全删除身份验证。

When you execute your code in Visual Studio you are running in the context of your own credentials, which I assume are enough to reach the web service. 当您在Visual Studio中执行代码时,您将在自己的凭据上下文中运行,我认为这些凭据足以访问Web服务。

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

相关问题 运行Windows应用程序时及时调试器错误 - just in time debugger error when running windows application 代码在控制台应用程序中有效,但在Windows Service中运行时不起作用 - Code works in a console application, but does not work when running in windows service 作为Windows服务运行时,MSMQ应用程序不处理排队的消息 - MSMQ Application does not process queued messages when running as Windows Service 将应用程序作为Windows服务运行时的汇编文件加载错误 - assembly file load error when running application as windows service 以 windows 服务运行 web 应用程序时拒绝连接到 localhost - Refused to connect to localhost when running web application as windows service 运行Windows服务时出现FileNotFoundException - FileNotFoundException when running a Windows Service 如何将调试器附加到在Windows Azure VM上运行的应用程序? - How to attach a debugger to an application running on Windows Azure VM? 如何在Windows服务中查看Windows窗体应用程序作为服务运行的应用程序 - How to View the Windows form application In Windows Service Application running as service 使用Windows Service检查应用程序是否正在运行 - Checking if an application is running using Windows Service 运行 Windows 服务应用程序而不安装它 - Running Windows Service Application without installing it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM