mshtml and the click event inside of a windows service.

  • Thread starter Thread starter Robert May
  • Start date Start date
R

Robert May

I have an application that uses the Ax web browser object. When I call the
IHTMLElement.click() method on an input button (<input type="submit"> or
<input type="button">), the click fires appropriately, if I'm running it
from a windows forms based application.

However, when I run the EXACT same code under a windows service, either as a
logged in user or as the local system account, the click fails to process.
Clicking on other elements (like <a>) works.

I've tried submitting the form directly, in cases where a submit occurs, but
can't do that either. Both GET and POST actions fail.

What am I doing wrong? Is there something that prohibits the onclick event
from firing for buttons when running as a service? Am I missing something?

Robert
 
Robert,

As a general rule, you should not try and access UI elements from within
a windows service. It's generally a bad idea.

Do you have the service set up to interact with the desktop? If not,
turn this on, and it might work. This would mean that your service would
always have to have a logged in user to run in order to work (and you can't
guarantee that).

To what end are you using the WebBrowser control?
 
Nicholas,

We are gathering the content from various web pages using c# scripts and
don't have the time to write something that would be capable of doing posts
and gets and parsing javascript to determine locations.

We want to have many threads of this automated process. In the future,
we'll write something that doesn't use the webbrowser control because of
issues like this, but we simply didn't have the resources to do so at this
time.

Suggestions?

Robert

Nicholas Paldino said:
Robert,

As a general rule, you should not try and access UI elements from
within a windows service. It's generally a bad idea.

Do you have the service set up to interact with the desktop? If not,
turn this on, and it might work. This would mean that your service would
always have to have a logged in user to run in order to work (and you
can't guarantee that).

To what end are you using the WebBrowser control?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
I have an application that uses the Ax web browser object. When I call the
IHTMLElement.click() method on an input button (<input type="submit"> or
<input type="button">), the click fires appropriately, if I'm running it
from a windows forms based application.

However, when I run the EXACT same code under a windows service, either
as a
logged in user or as the local system account, the click fails to
process.
Clicking on other elements (like <a>) works.

I've tried submitting the form directly, in cases where a submit occurs,
but
can't do that either. Both GET and POST actions fail.

What am I doing wrong? Is there something that prohibits the onclick
event
from firing for buttons when running as a service? Am I missing
something?

Robert
 
Robert,

I think the only other option would be to access MSHTML yourself, and
load the content into there. I don't know if it needs access to the desktop
(it shouldn't, if the host doesn't support it), but you will have to do a
lot of interop to load your documents (depending on where you get them
from).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
Nicholas,

We are gathering the content from various web pages using c# scripts and
don't have the time to write something that would be capable of doing
posts and gets and parsing javascript to determine locations.

We want to have many threads of this automated process. In the future,
we'll write something that doesn't use the webbrowser control because of
issues like this, but we simply didn't have the resources to do so at this
time.

Suggestions?

Robert

Nicholas Paldino said:
Robert,

As a general rule, you should not try and access UI elements from
within a windows service. It's generally a bad idea.

Do you have the service set up to interact with the desktop? If not,
turn this on, and it might work. This would mean that your service would
always have to have a logged in user to run in order to work (and you
can't guarantee that).

To what end are you using the WebBrowser control?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
I have an application that uses the Ax web browser object. When I call
the
IHTMLElement.click() method on an input button (<input type="submit"> or
<input type="button">), the click fires appropriately, if I'm running it
from a windows forms based application.

However, when I run the EXACT same code under a windows service, either
as a
logged in user or as the local system account, the click fails to
process.
Clicking on other elements (like <a>) works.

I've tried submitting the form directly, in cases where a submit occurs,
but
can't do that either. Both GET and POST actions fail.

What am I doing wrong? Is there something that prohibits the onclick
event
from firing for buttons when running as a service? Am I missing
something?

Robert
 
Nicholas,

We actually ARE using MSHTML. We have the browser navigate, get the doc and
then parse through the document. We're then calling the
IHTMLElement.click() method and expecting this to do the navigation back
with the browser.

Under a windows service, it doesn't work. :( Even if we get the form that
we're trying to submit and call submit, it doesn't work. It's like post
backs are disabled in windows services.

Robert

Nicholas Paldino said:
Robert,

I think the only other option would be to access MSHTML yourself, and
load the content into there. I don't know if it needs access to the
desktop (it shouldn't, if the host doesn't support it), but you will have
to do a lot of interop to load your documents (depending on where you get
them from).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
Nicholas,

We are gathering the content from various web pages using c# scripts and
don't have the time to write something that would be capable of doing
posts and gets and parsing javascript to determine locations.

We want to have many threads of this automated process. In the future,
we'll write something that doesn't use the webbrowser control because of
issues like this, but we simply didn't have the resources to do so at
this time.

Suggestions?

Robert

Nicholas Paldino said:
Robert,

As a general rule, you should not try and access UI elements from
within a windows service. It's generally a bad idea.

Do you have the service set up to interact with the desktop? If not,
turn this on, and it might work. This would mean that your service
would always have to have a logged in user to run in order to work (and
you can't guarantee that).

To what end are you using the WebBrowser control?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have an application that uses the Ax web browser object. When I call
the
IHTMLElement.click() method on an input button (<input type="submit">
or
<input type="button">), the click fires appropriately, if I'm running
it
from a windows forms based application.

However, when I run the EXACT same code under a windows service, either
as a
logged in user or as the local system account, the click fails to
process.
Clicking on other elements (like <a>) works.

I've tried submitting the form directly, in cases where a submit
occurs, but
can't do that either. Both GET and POST actions fail.

What am I doing wrong? Is there something that prohibits the onclick
event
from firing for buttons when running as a service? Am I missing
something?

Robert
 
Robert,

Yes, you are using MSHTML, but you are getting it from a WebBrowser
control, and I believe that this is the issue. You need to create an
instance of MSHTML.HTMLDocument yourself, and load the content into there.
The document on it's own doesn't require interaction with the desktop (even
though you still have access to javascript events and the like).

You will have to create an IPersistMoniker definition, and then upload
your content through the call to Load. It's a lot of work, but the only way
to untie the document from the visualizer (which is the control).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
Nicholas,

We actually ARE using MSHTML. We have the browser navigate, get the doc
and then parse through the document. We're then calling the
IHTMLElement.click() method and expecting this to do the navigation back
with the browser.

Under a windows service, it doesn't work. :( Even if we get the form that
we're trying to submit and call submit, it doesn't work. It's like post
backs are disabled in windows services.

Robert

Nicholas Paldino said:
Robert,

I think the only other option would be to access MSHTML yourself, and
load the content into there. I don't know if it needs access to the
desktop (it shouldn't, if the host doesn't support it), but you will have
to do a lot of interop to load your documents (depending on where you get
them from).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert May said:
Nicholas,

We are gathering the content from various web pages using c# scripts and
don't have the time to write something that would be capable of doing
posts and gets and parsing javascript to determine locations.

We want to have many threads of this automated process. In the future,
we'll write something that doesn't use the webbrowser control because of
issues like this, but we simply didn't have the resources to do so at
this time.

Suggestions?

Robert

in message Robert,

As a general rule, you should not try and access UI elements from
within a windows service. It's generally a bad idea.

Do you have the service set up to interact with the desktop? If
not, turn this on, and it might work. This would mean that your
service would always have to have a logged in user to run in order to
work (and you can't guarantee that).

To what end are you using the WebBrowser control?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have an application that uses the Ax web browser object. When I call
the
IHTMLElement.click() method on an input button (<input type="submit">
or
<input type="button">), the click fires appropriately, if I'm running
it
from a windows forms based application.

However, when I run the EXACT same code under a windows service,
either as a
logged in user or as the local system account, the click fails to
process.
Clicking on other elements (like <a>) works.

I've tried submitting the form directly, in cases where a submit
occurs, but
can't do that either. Both GET and POST actions fail.

What am I doing wrong? Is there something that prohibits the onclick
event
from firing for buttons when running as a service? Am I missing
something?

Robert
 
Hi Nicholas,
Yes, you are using MSHTML, but you are getting it from a WebBrowser
control, and I believe that this is the issue. You need to create an
instance of MSHTML.HTMLDocument yourself, and load the content into there.
The document on it's own doesn't require interaction with the desktop (even
though you still have access to javascript events and the like).

You will have to create an IPersistMoniker definition, and then upload
your content through the call to Load. It's a lot of work, but the only way
to untie the document from the visualizer (which is the control).

That's a good starting point:

"Writer", hosted on the GotDotNet Workplaces.
Quite high quality [Lutz Roeder ("Reflector") is involved].

Another project:

http://www.itwriting.com/htmleditor/index.php

As far I can recall, the project embeds MSHTML exactly as you
recommend, but I don't think that IPersistMoniker is used.

bye
Rob
 
Robert,

This is definitely a good place to start. Granted, you won't want to
provide the visual elements in hosting (because I assume that would bring
you back to the same problem you had before), but it will show you how to
host MSHTML.

Check out the section of MSDN titled "Reusing MSHTML", located at (watch
for line wrap):

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/hosting/hosting.asp

It will give you a good idea of where to start. Everything is done in
C++, but can be converted to interop calls.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert Jordan said:
Hi Nicholas,
Yes, you are using MSHTML, but you are getting it from a WebBrowser
control, and I believe that this is the issue. You need to create an
instance of MSHTML.HTMLDocument yourself, and load the content into
there. The document on it's own doesn't require interaction with the
desktop (even though you still have access to javascript events and the
like).

You will have to create an IPersistMoniker definition, and then
upload your content through the call to Load. It's a lot of work, but
the only way to untie the document from the visualizer (which is the
control).

That's a good starting point:

"Writer", hosted on the GotDotNet Workplaces.
Quite high quality [Lutz Roeder ("Reflector") is involved].

Another project:

http://www.itwriting.com/htmleditor/index.php

As far I can recall, the project embeds MSHTML exactly as you
recommend, but I don't think that IPersistMoniker is used.

bye
Rob
 
Back
Top