所以我创建了一个服务,每隔x分钟就会检查一次服务器并收到来自它的回复。回复是睡眠或命令。接收扫描命令,服务打包并刻录大量文件并将其发送到服务器。 在调试模式期间,我的应用运行完全正常我可以逐步完成代码,所有内容都会被触发,客户端和服务器之间的通信也很完美。
然而。部署我的服务后,它会在收到扫描命令时崩溃。我查看了Windows事件查看器,发现了这个:
Application: Client.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info:
System.Net.WebException Stack: at
System.Net.FtpWebRequest.GetRequestStream() at
tcpClient.ftpClass.upload(System.String, System.String) at
Client.Service1.checkInCycle(System.String) at
Client.Service1.Callback(System.Object) at
System.Threading.TimerQueueTimer.CallCallbackInContext(System.Object) at
System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,
System.Threading.ContextCallback, System.Object, Boolean) at
System.Threading.TimerQueueTimer.CallCallback() at
System.Threading.TimerQueueTimer.Fire() at
System.Threading.TimerQueue.FireNextTimers() at
System.Threading.TimerQueue.AppDomainTimerCallback()
我在FTPWebRequest中可以想到的唯一可能的失败点是timeoutVal,但是我使用以下内容将其更改为无限:
request.Timeout = -1;
关于为什么会发生这种情况的任何想法?
答案 0 :(得分:1)
我在FTPWebRequest中可以想到的唯一可能的失败点是timeoutVal
根据msdn System.Net.FtpWebRequest.GetRequestStream()
可以抛出这些例外:
InvalidOperationException
WebException
ProtocolViolationException
。您明确提供的异常信息表明您遇到了WebException
:
异常信息:System.Net.WebException
根据我之前提到的msdn文章,当
时发生无法建立与FTP服务器的连接。
您应该检查的可能原因:
考虑到您调试它没有任何问题,并且您只在部署后遇到它,我认为您的FTP服务器可以从您部署服务的环境中无法访问。
答案 1 :(得分:0)
添加CodingFeles所说的内容:
应该指出这是一个愚蠢的错误,由至少10个小时的编程直到上午9点....即。在这一点上我脑子震撼并在没有意识到的情况下引入了错误:
引入错误是因为出于某些愚蠢的原因,我意外地评论了FTP程序的网络凭据,以及所有内容源自的程序。
如果您还遇到此问题,请不要说这将是您的解决方案。但请确保您拥有服务器的正确网络凭据,并且实际上是通过了这些凭据:
request.Credentials = new NetworkCredential("user", "pass");