programmatically access a web app via a windows service

  • Thread starter Thread starter doug.h.taylor.accipitersoftware.com
  • Start date Start date
D

doug.h.taylor.accipitersoftware.com

Hi,

I need a general direction. I don't even know where to start
researching how to do this.

I have an existing dot net web application (It's mine, I wrote it)
that has some text fields and a button. The code-behind click event
of the button sends an SNPP conversation to a pager server.

I also have an existing dot net windows service running on a dedicated
machine with special hardware that can listen for and receive the
pages via radio. The purpose of the service is to monitor various
paging applications. It does so by continuously looping through a set
of test pages and listens for them to return.

My client now wants me to "monitor" the web application. I need to
have the windows service execute the web application and send a page
as if a human had done so. I have no idea how to proceed.

Is there an obvious definitive way of doing this that I am
overlooking? Does anyone have any creative ideas? If Microsoft is
monitoring this, do you have any suggestions?

Thanks in advance,
Doug
 
Hi Doug,

Thanks for your post. .NET Class Library provides several classes (say,
System.Net.HttpWebRequest) which can be used to access web pages. I believe
the following MSDN article and sample are helpful:

HttpWebRequest Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemnethttpwebrequestclasstopic.asp

SAMPLE: Visual C# .NET Networking Classes HTTP Internet Client
http://support.microsoft.com/?id=303436

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tian Min Huang,

Thanks for the response. I have investigated HttpWebRequest and
HttpWebResponse but these won't let me put text in a textbox and push
a button. I can simulate that activity and send a post to the server
as if a button click caused a postback, but to do that in Dot Net, I'd
have to correctly populate that hidden field with the encoded state
data. I don't expect that to be very do-able.

I seem to be having the most luck with the interop
SHDocVw.InternetExplorer. I was hoping, however, that there would be
a way to do this in managed code.

Have I missed anything? Is this my only option?

Thanks,
Doug
 
Hi Doug,

Thanks for your update. The following KB article describes using Web
Browser control in .NET, please check it on your side. After loading a web
page in the control, then you can send keyboard messages to simulate a user
input and operation.

Web Browser in C# and VB.NET
http://www.c-sharpcorner.com/Internet/WebBrowserInCSMDB.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tian Min Huang,

Thanks for the link. It was very informative. I have, however,
looked into this and, unless I'm missing something, it won't work in
this case.

Since this has got to work in a Windows Service it must be completely
free of any UI. In a proof-of-concept windows application, I was able
to use it as a control just fine, but when I tried to simply
instantiate it as an object it complained. It seems to really want to
write to something and I couldn't placate it.

I was able to instantiate an instance of the InternetExplorer class in
the same DLL and it seemed happy not having a UI available. I am
worried about using this object for two reasons.

First, this seems like a pretty bulky object to leave lying around or
to be constantly creating and destroying.

Second, this Windows Service must continue looping 24/7 for months at
a time. Is this object "leak proof"?

Thanks again,
Doug
 
Hi Doug,

Thanks for your response. I'd like to share the following information with
you:

1. Generally speaking, a Windows Service is desinged to be running
background without UI. Still, we are able to create a visible/hidden form
within Service as long as running the windows service in Local System
account, allowing service to interact with desktop.

2. I am glad to hear that you were able to automate Internet Explorer (by
instantiating an instance of the IE class). That is, you start Internet
Explorer from within your service. I believe this is a good method and
there is no need to worry about the issues like "IE is leak proof".

I look forward to your feedback.

Have a great day!
Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tian Min Huang,

Sorry for the delay. I seem to have had a setback. the solution
using the InternetExplorer object works perfectly in a Windows
application and a console application (which is where I developed it),
but when I put it in my Windows service, it stops functioning.

I can call the "navigate" method without incurring an error, but the
object never fires any of its events unlike in the other environments.

I still can't help feeling that the problem is that the IE object
contains forms (visible or not) which are forbidden in a Windows
service.

Any more thoughts?

Thanks,
Doug
 
Hi Doug,

Thanks for your resposne.

As you know, the desktops of the interactive window station, Winsta0, can
be made to display a user interface and receive user input, but only one of
these desktops at a time is active. As you know, a service will be created
in the non-interactive window station by default, I believe that's the
cause of this problem. I recommend you configure your service as
interactive service by running the windows service in Local System account
and allowing service to interact with desktop, and then check whether or
not the problem still exists. Please refer to the following MSDN article
for detailed information:

Interactive Services
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/interactive_services.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Doug,

Thanks for your response. I'd like to share the following information with
you:

1. Generally speaking, a Windows Service is desinged to be running
background without UI. Still, we are able to create a visible/hidden form
within Service as long as running the windows service in Local System
account, allowing service to interact with desktop.

2. I am glad to hear that you were able to automate Internet Explorer (by
instantiating an instance of the IE class). That is, you start Internet
Explorer from within your service. I believe this is a good method and
there is no need to worry about the issues like "IE is leak proof".

I look forward to your feedback.

Have a great day!
Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

IE webcontrol is VERY LEAKY. I have a VB test case use IE webcontorl
that continuously hit a few pages on a website. The system loose 128K of
RM every loop. A 1GB RAM system will run out memory completely in over night
test. Search Google and you will find other had asked MS for fix for this.
There is not response from MS about this at all.
 
Back
Top