我正在创建WCF web services那个automata internet explorer。有多个 Web 服务调用需要访问Internet Explorer. 但是,由于WCF服务托管在IIS所有对 Web 服务的调用都在会话 0 中执行。现在要访问同一个实例,Internet Explorer我使用SHDocVw.InternetExplorer.HWND返回实例的窗口句柄的属性Internet Explorer。在下面的代码中,当在窗口句柄上作为WCF服务执行时,IIS 7由于会话 0 隔离,总是返回 0。此外,我无法重新连接到同一个IE实例或循环浏览所有打开的IE窗口。我可以枚举进程列表并查找在会话 0 中打开的每个IE窗口的进程 ID,但不能强制System.Diagnostics.Process转换为SHDocVw.InternetExplorer对象。
下面是我的代码:
public int GetWhd()
{
InternetExplorer ie = new InternetExplorer();
ie.Visible = true;
return ie.HWND;
}
public int SetWhd(string whd)
{
int wh = Int32.Parse(whd);
InternetExplorer ie = null;
ShellWindows s = new ShellWindows();
foreach (SHDocVw.InternetExplorer ie1 in s)
{
try
{
if (ie1.HWND == wh)
{
ie = ie1;
break;
}
}
catch { return 2; }
}
if (ie != null) { ie.Navigate("www.google.com"); return 1; }
return 0;
}
任何帮助都感激不尽。