简体   繁体   English

如何在 WCF 服务中使用 CefSharp?

[英]How do you use CefSharp in a WCF Service?

I am trying to use the CefSharp.OffScreen(41.0.0) Nuget Package within a WCF Service Application, and I'm getting the following error while trying to run the service from Visual Studio 2013:我正在尝试在 WCF 服务应用程序中使用CefSharp.OffScreen(41.0.0) Nuget 包,并且在尝试从 Visual Studio 2013 运行该服务时出现以下错误:

Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies.无法加载文件或程序集“CefSharp.BrowserSubprocess.Core.DLL”或其依赖项之一。 The specified module could not be found.指定的模块无法找到。

Description: An unhandled exception occurred during the execution of the current web request.说明:在执行当前 Web 请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code.请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.BrowserSubprocess.Core.DLL' or one of its dependencies.异常详细信息:System.IO.FileNotFoundException:无法加载文件或程序集“CefSharp.BrowserSubprocess.Core.DLL”或其依赖项之一。 The specified module could not be found.指定的模块无法找到。

The mentioned assembly is present in the project's bin folder as well as all the required assemblies listed on CefSharp's Website .提到的程序集存在于项目的 bin 文件夹中,以及CefSharp 网站上列出的所有必需程序集。 If there is in fact another assembly required I haven't figured out what it is.如果实际上需要另一个程序集,我还没有弄清楚它是什么。

A few other points worth mentioning:还有几点值得一提:

  • It is easy to reproduce: Start with VS2013's "WCF Service Application" template simply added the CefSharp.Offscreen Nuget Package.很容易重现:从VS2013的“WCF服务应用程序”模板开始,简单地添加了CefSharp.Offscreen Nuget Package。
  • I build the project in x86.我在 x86 中构建项目。
  • CefSharp also depends on the Visual Studio C++ 2012 redistributables. CefSharp 还依赖于 Visual Studio C++ 2012 可再发行组件。 I copied those file into the bin folder but still get the same error.我将这些文件复制到 bin 文件夹中,但仍然出现相同的错误。
  • I tried the solutions in the SO question here , to no avail.我在这里尝试了 SO 问题中的解决方案,但无济于事。
  • CefSharp works fine when referenced from a Console Application or WPF Application.当从控制台应用程序或 WPF 应用程序引用时, CefSharp工作正常。

Few points,几点,

IIS cannot access Desktop IIS 无法访问桌面

So you can't run anything that needs a desktop.所以你不能运行任何需要桌面的东西。 Your Console and WPF application has access to Desktop and are called user interactive processes.您的控制台和 WPF 应用程序可以访问桌面并称为用户交互进程。

CEF needs desktop CEF 需要桌面

Cef will need Window manager to create window, without which it cannot render page. Cef 需要窗口管理器来创建窗口,没有它就不能渲染页面。 This is the reason, the error is misleading here, as IIS cannot load dependent assemblies which require Desktop interaction unless Allow service to interact with Desktop is selected for IIS process in Windows Services.这就是原因,这里的错误具有误导性,因为 IIS 无法加载需要桌面交互的依赖程序集,除非在 Windows 服务中为 IIS 进程选择了Allow service to interact with Desktop

Console application is only option with Login控制台应用程序是登录的唯一选项

You will have to run your application as console and you will need to login to desktop, allowing IIS to interact with desktop is not a good option and I don't even know what kind of problems it might have.您必须将应用程序作为控制台运行,并且需要登录到桌面,允许 IIS 与桌面交互不是一个好的选择,我什至不知道它可能有什么样的问题。

You can set your server to auto login to some user by modifying registry and set your console application in your startup.您可以通过修改注册表将您的服务器设置为自动登录到某个用户,并在启动时设置您的控制台应用程序。 So this way everytime server will be restarted, your server will automatically login to specified user and your console app will start.这样每次服务器重新启动时,您的服务器将自动登录到指定的用户,您的控制台应用程序将启动。 (Windows 8.1 has little difficulty but you will get some solution). (Windows 8.1 没有什么困难,但你会得到一些解决方案)。

Custom Windows Service with Desktop Access具有桌面访问权限的自定义 Windows 服务

You can change your application type to Windows Service instead of Console and you can install your windows service that allows access to desktop shown in this article, beware, there are problems that this will work only if somebody is logged on to server.您可以将应用程序类型更改为 Windows 服务而不是控制台,并且您可以安装允许访问本文中显示的桌面的 Windows 服务,请注意,存在一些问题,只有当有人登录到服务器时,这才会起作用。

http://www.codeproject.com/Articles/4891/Interact-With-Desktop-when-Installing-Windows-Serv http://www.codeproject.com/Articles/4891/Interact-With-Desktop-when-Installing-Windows-Serv

PhantomJS headless browser PhantomJS 无头浏览器

There is PhantomJS headless browser which you can run in IIS/Windows Service without need to interact with desktop, however you will need to shift your code to JavaScript instead of C#.有 PhantomJS 无头浏览器,您可以在 IIS/Windows 服务中运行而无需与桌面交互,但是您需要将代码转换为 JavaScript 而不是 C#。 There are other libraries to manage PhantomJS from your app as well.还有其他库可以从您的应用程序管理 PhantomJS。

根据此链接,此问题的解决方案似乎是在 [STAThread] 线程中运行 CefSharp 代码。

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

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