473,503 Members | 12,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with IE automation when used in webservice

hi guys,

I have encountered a problem with IE automation (.NET 2.0, C#, mshtml,
SHDocVw). I am writing a class for manipulating specific html pages
with frames. It is supposed to be used from a web service. The
problem is that when I use the InternetExplorer object in web service,
it seems like the underlying IE doesn't support frames. When I try to
access HTMLDocumentClass.frames property I get the following exception:

Specified cast is not valid.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at mshtml.HTMLDocumentClass.get_frames()
at myclass.mymethods()

the code lines, that cause the exception:

ie = new InternetExplorer();
object dummy = null;
ie.Navigate("myurl", ref dummy, ref dummy, ref dummy, ref dummy);
// ... omitted code assuring the html document is loaded ...
HTMLDocumentClass iedoc = (HTMLDocumentClass)ie.Document;
FramesCollection frames = iedoc.frames; // this throws the exception
....

(when the same code is used in a "normal" windows forms application, it
works fine).

Feb 13 '06 #1
4 7917

Johny_W wrote:
hi guys,

I have encountered a problem with IE automation (.NET 2.0, C#, mshtml,
SHDocVw). I am writing a class for manipulating specific html pages
with frames. It is supposed to be used from a web service. The
problem is that when I use the InternetExplorer object in web service,
it seems like the underlying IE doesn't support frames. When I try to
access HTMLDocumentClass.frames property I get the following exception:

Specified cast is not valid.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at mshtml.HTMLDocumentClass.get_frames()
at myclass.mymethods()

the code lines, that cause the exception:

ie = new InternetExplorer();
object dummy = null;
ie.Navigate("myurl", ref dummy, ref dummy, ref dummy, ref dummy);
// ... omitted code assuring the html document is loaded ...
HTMLDocumentClass iedoc = (HTMLDocumentClass)ie.Document;
FramesCollection frames = iedoc.frames; // this throws the exception
...

(when the same code is used in a "normal" windows forms application, it
works fine).


I'm having the same problem. Seems that all HTMLDocumentClass
properties that reference UI elements fail to get marshalled by COM
Interop when creating a new instance of the HTMLDocumentClass in web
services. Apparently web services execute according to a policy that
restricts the creation of UI elements. I'm trying to get at the
parentWindow property in order to be able to correctly release
resources when I'm done with the HTML parser but no go. When I attempt
to view the parentWindow property in the debugger the property
indicates that a Invalid Cast Exception has occurred. Thanks to this
foolishness I am frequently getting mshtml faults in w3wp.exe after
which time the web service becomes non functional. My guess is that
the windows are getting created but barring a reference to them in the
mshtml RCW wrapper there's not way to correctly release the reference
to the underlying COM object and it's associated resources.

The upshot seems to be that you can't create an HTMLDocumentClass
instance without creating several windows at the same time. You'll
notice that in a regular app the parentWindow is initialized correctly
and can be closed along with it's own parent window with a little
trickery. You'll also notice in task manager that memory and handles
get released correctly at the same time. Nevertheless in a web app or
web service it looks like you're screwed. Can't get to those windows.

If only Microsoft had modularized the HTML Parser in mshtml.dll and
made it independent of the UI we could all get a little rest.

Mar 10 '06 #2
OK. I got this to work. Thanks to a reply to another post.

I create a thread and set it's apartment state to STA. I execute the
parsing code in that thread and am able to access the associated
windows objects. I imagine this will for frames as well.

Mar 10 '06 #3
I tried your solution, but I get UnauthorizedAccessException
immediately when I'm creating InternetExplorer object.

details:
System.UnauthorizedAccessException: Retrieving the COM class factory
for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed
due to the following error: 80070005. at MyMethod()

In web.config I have set impersonation to my administrator account and
also Full trust. Is it possible that the created thread has weaker
permissions?

Mar 15 '06 #4
Johny,

You might find these links useful:

1) blog.crowe.co.nz/archive/2006/03/02/589.aspx
2) http://support.microsoft.com/default...b;en-us;257757

Hope this helps

Sriram

Mar 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9467
by: ramarnath | last post by:
Problem in sending datatime format to the .net webservice from php. description follows. I've created a .net webservice. ..Net Webservice: <WebMethod()> _ Public Function HelloDate(ByVal...
2
5682
by: Miguel | last post by:
Hi, I'm developing an application in C# with Windows Forms for my company that is similar to the MSN Messenger. This application uses a webservice for registering users, etc... and as 2...
1
1585
by: Smugsboy | last post by:
Hi, I have a problem with a web service proxy written in .NET and used from VS6's C++ as COM object. This proxy works great when used from a .NET application. It does not seem to work when used...
5
2687
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web...
5
19560
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
1
1946
by: Mahesh Devjibhai Dhola | last post by:
Hi, Scenario: The webservice was developed on windows 2000 Pro and deployed previously on windows XP pro for testing. We have tested for many days. The client for that service was 30+ and...
0
1345
by: Rob C | last post by:
I have several methods implemented in a webservice written in C#. The methods execute SQL against a SQL Server 2005 db and returns a Dataset (as XML). I am utilizing the webservice from a VC++...
0
2663
by: =?Utf-8?B?TWFuaQ==?= | last post by:
Hi All, Problem in deploying my WebService developed using Asp.net WebServices 2005. I have designed simple WebService using Asp.net Webservices 2.0 , The webservice look this , using System;...
15
5326
by: =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= | last post by:
Hi All, We are in the process of Upgrade Excel 2003 (Office 2003) to Excel 2007 (Office 2007) for one of web application. This web application is using Excel (Pivot Table) reports. With Excel...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.