简体   繁体   English

您可以在WCF服务下运行WebBrowser吗?

[英]Can you run WebBrowser under a WCF service?

I'm currently trying to move over a screen-scraping program (c# forms application) to a WCF service. 我目前正在尝试将屏幕抓取程序(C#窗体应用程序)移到WCF服务。

The screen-scraping program uses WebBrowser to grab info off several pages for which there is no API. 屏幕抓取程序使用WebBrowser来从几个没有API的页面上抓取信息。 I would like to know if you can run WebBrowser in a service let alone a form. 我想知道您是否可以在服务中运行WebBrowser ,更不用说表单了。 I'm currently developing on XP to be release on Server 2003. 我目前正在XP上开发,该版本将在Server 2003上发布。

Currently when running unit test, I can only see the WebBrowser if it was made on the "Unit Test" side and even then I need to manually pop up MessageBox 'es to get WebBrowser to stop from not navigating with a blank screen. 当前,在运行单元测试时,我只能看到WebBrowser,如果它是在“单元测试”侧进行的,即使如此,我仍然需要手动弹出MessageBox来使WebBrowser停止不显示空白屏幕。

The program is being moved and split up since we are having multi-threading issues. 由于我们遇到多线程问题,因此该程序正在移动和拆分。

You would be better off using a headless browser like Phantom.js: http://www.phantomjs.org/ . 使用像Phantom.js这样的无头浏览器会更好: http ://www.phantomjs.org/。 It offers significant features and has no problem being executed wherever you need like a regular command - line program. 它具有重要的功能,并且像常规的命令行程序一样,在您需要的任何地方执行都没有问题。

In thinking about this, realize that each instance of the WebBrowser control is actually an instance of Internet Explorer. 在考虑这一点时,请意识到WebBrowser控件的每个实例实际上都是Internet Explorer的一个实例。 Your question then becomes one of having a service start multiple instances of Internet Explorer. 然后,您的问题就成为一项服务启动Internet Explorer的多个实例之一。

But Internet Explorer is an interactive application. 但是Internet Explorer是一个交互式应用程序。 It expects to control the keyboard and mouse when it has the focus. 它希望在获得焦点时控制键盘和鼠标。

  • Which keyboard and mouse do you want it to control when running in the server? 您希望它在服务器中运行时控制哪种键盘和鼠标?
  • How many keyboards and mice does your server have? 您的服务器有多少个键盘和鼠标?

You could find some way for the service to launch a Remote Desktop connection and start up your Windows Forms application. 您可以找到该服务启动远程桌面连接并启动Windows Forms应用程序的某种方法。 You could then have your Windows Forms application host a WCF service, and the two services could talk to each other. 然后,您可以让Windows窗体应用程序托管WCF服务,并且这两个服务可以相互通信。 I have seen this sort of thing done when it was necessary to automate a specialized interactive program which could not be made into a service. 我已经看到了这种事情的完成,这是必要的,它需要自动化无法制作成服务的专用交互式程序。

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

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