简体   繁体   English

从 webform 调用控制台应用程序(WCF 服务)的问题

[英]Problem with calling Console application (WCF Service) from webform

I am using a ASP.net webform application to run an existing console application which get all records from DB and send them through a third party WCF service.我正在使用 ASP.net 网络表单应用程序来运行现有的控制台应用程序,该应用程序从数据库获取所有记录并通过第三方 WCF 服务发送它们。 Locally everything is working fine.本地一切正常。 When I run the application it opens the console, gets the records and sends them.当我运行应用程序时,它会打开控制台,获取记录并发送它们。 But now I pushed my files over to Test server along with the exe file and related config files.但是现在我将我的文件连同 exe 文件和相关的配置文件一起推送到了测试服务器。 But when I access the application through the browser (test url) I get the same error message time and again and I don't see the console window.但是当我通过浏览器(测试 url)访问应用程序时,我一次又一次地收到相同的错误消息,并且我没有看到控制台 window。 Sometimes everything works fine but never two times in a row.有时一切正常,但从来没有连续两次。

The error message is:错误信息是:

"There was no end point listening at '.....svc' that could accept message. This is often caused by incorrect address or soap action. 

System.net.webexception. Remote name could not be resolved 
at System.Net.HttpWebRequest.GetRequestStream 
at System.ServiceModel.Channels.HttpOutput.Webrequest.HttpOutput.GetOutputStream()

The code I have used in the webform to call console application is:我在 webform 中用于调用控制台应用程序的代码是:

ProcessStartInfo p = new ProcessStartInfo();
p.Arguments = _updateNow.ToString();
p.FileName="something";
p.UseShellExecute = false;// tried true too without luck
Process.Start(p);

Error message denotes "there is no end point" and sounds like there is problem with the WCF service but if I double click the executable in Test there is no problem.错误消息表示“没有终点”,听起来 WCF 服务有问题,但如果我在测试中双击可执行文件,则没有问题。 What could be the possible problem or should I redo the console application functionality to my main webform application?可能是什么问题,或者我应该为我的主 webform 应用程序重做控制台应用程序功能吗?

Update: After adding Thread.Sleep(3000) after Process.Start(p), I'm having no problem.更新:在 Process.Start(p) 之后添加 Thread.Sleep(3000) 后,我没有问题。 So seems like main application is not waiting for the batch process to complete.所以似乎主应用程序没有等待批处理完成。 How to solve this problem?如何解决这个问题呢?

It seems like there is a short delay between starting the console application and the WCF web service becoming initialise and available to use - this is to be expected.似乎在启动控制台应用程序和 WCF web 服务变得初始化并可以使用之间有短暂的延迟 - 这是意料之中的。

You could either:您可以:

  • Work around the issue using Thread.Sleep() and possibly with a couple of catch - retry blocks.使用Thread.Sleep()并可能使用几个 catch - retry 块来解决此问题。
  • You could have the console application report to the creating process when it is ready to recieve requests (for example by having it write to the standard output and using redirected streams).您可以让控制台应用程序在准备好接收请求时向创建过程报告(例如,通过让它写入标准 output 并使用重定向流)。

However at this point I'd probably reconsider the architecutre slightly - starting a new process is relativley costly, and on top of that initialising a WCF serice is also relatively costly too.然而,在这一点上,我可能会稍微重新考虑一下架构——开始一个新的过程是相对昂贵的,最重要的是,初始化一个 WCF 服务也相对昂贵。 If this is being done once per request then as well as the above timing issues you are also incurring performance penalties.如果每个请求都执行一次,那么除了上述时间问题之外,您还会招致性能损失。

Is it not possible to change the architecutre slightly so that a single external process (for example a Windows service) is used for all requests instead of spawning a new process each time?是否可以稍微更改架构,以便将单个外部进程(例如 Windows 服务)用于所有请求,而不是每次都生成一个新进程?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM