Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
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.

C#
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);


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.
Posted
Updated 8-Dec-11 21:47pm
v3
Comments
Sergey Alexandrovich Kryukov 8-Dec-11 16:14pm    
Which WebBrowser class? There are more than one. Fully qualified name, please, with name space. Tag the UI library, please.
--SA

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900