Web服务问题中的Web浏览器 [英] webbrowser in web service problem

查看:70
本文介绍了Web服务问题中的Web浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我的目标是编写从html字符串打印的Web服务方法,我是使用System.Windows.Forms.WebBrowser类实现的.

Hi.
My goal is writing the web service method that print from a html string.I did it using a System.Windows.Forms.WebBrowser class.

const short PRINT_WAITFORCOMPLETION = 2;
  const int OLECMDID_PRINT = 6;
  const int OLECMDEXECOPT_DONTPROMPTUSER = 2;
  var browser = new WebBrowser();
  browser = Browser;
  while (browser.ReadyState != WebBrowserReadyState.Complete)
  Application.DoEvents();
  dynamic ie = browser.ActiveXInstance;
  HtmlDocument htmld = (HtmlDocument)browser.Document;
  htmld .Body.InnerHtml = HtmlString;
  ie.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, PRINT_WAITFORCOMPLETION);



我收到以下错误:

"TargetInvocation异常"和无法获取WebBrowser控件的窗口句柄.不支持无窗口ActiveX控件"

请帮助解决问题.



I get the following error:

"TargetInvocation exception" and "Unable to get window handle for WebBrowser Control. Windowless ActiveX control not Supported"

Please Help how to resolve it.

推荐答案

这就是它的确切含义.此类只能由某些UI类托管使用.我不知道,Forms,WPF-您未指定尝试使用的WebBrowser类-请参阅我的问题.但是,没关系,因为…
在Web服务中使用任何UI控件都是毫无意义的.即使有可能,谁能看到UI? :-)

即使您的Web服务确实确实需要充当Web客户端,也可以使用System.Net.HttpWebRequest,请参见:
http://msdn.microsoft.com/en-us/library/system.net. httpwebrequest.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.net. webrequest.aspx [ ^ ](请参见此处的代码示例).

—SA
This is exactly what it is. This class can be only used is hosted by some UI class. I don''t know, Forms, WPF — you did not specify what WebBrowser class you tried to use — please see my question. However, it does not matter, because…

Using any UI controls in a Web Service is absolutely pointless. Even if it was possible, who would see the UI?! :-)

Even if your Web Service really needs to act as a Web client, which is fine, you can use System.Net.HttpWebRequest, see:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^] (see the code sample here).

—SA


这篇关于Web服务问题中的Web浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆