[英]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.