Am trying to print a file from server side via a WCF service deployed on IIS machine. The following code gets worked on Win 2oo3 machine perfectly. But the same code is throwing a COM exception. Any idea about this. I guess its related to some permissions. Here is the code
public void Print(string htmlFilename, string printer, short copies)
{
string currDefault = string.Empty;
try
{
currDefault = GetDefaultPrinter();
myPrinters.SetDefaultPrinter(printer);
for (int i = 0; i < copies; i++)
{
documentLoaded = false;
documentPrinted = false;
InternetExplorer ie = new InternetExplorer ();
ie.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(ie_DocumentComplete);
ie.PrintTemplateTeardown += new SHDocVw.DWebBrowserEvents2_PrintTemplateTeardownEventHandler(ie_PrintTemplateTeardown);
object missing = Missing.Value;
ie.Navigate(htmlFilename, ref missing, ref missing, ref missing, ref missing);
while (!documentLoaded && ie.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT) != SHDocVw.OLECMDF.OLECMDF_ENABLED)
Thread.Sleep(100);
ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, ref missing, ref missing);
ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref missing, ref missing);
while (!documentPrinted)
Thread.Sleep(100);
ie.DocumentComplete -= ie_DocumentComplete;
ie.PrintTemplateTeardown -= ie_PrintTemplateTeardown;
ie.Quit();
}
}
catch { throw; }
finally
{
myPrinters.SetDefaultPrinter(currDefault);
}
}
And the Com Exception is as below exactly while creating an object for internetexplorer.
[ERRORLOG] Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) [/ERRORLOG]
Moreover if i try to create an object as InternetExplorerMedium. then its working in 2008 but not in Win server 2003. I was very much clue less... Any help regarding will help a lot.
Regards, Pavan N
Finally i changed my own logic itself. I observed lot of difference w.r.t IE. especially IE9. all the DCOM seetings will be different. so with the name InternetExplorer ie = new InternetExplorer (); you cant create any object. its not either related to permission or OS. its related to IE version. Above code works only upto IE8.