Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to set up a monitoring service for a database. Originally I had a windows service running on the same machine as the database and querying the database every 10 minutes. It was possible to change the time automatically by changing a value that I was storing in the machine's registry.

 

I have been told that I need to relocate this service, as if the machine goes down, the service will not be available. I have been told also that opening the sql server (2005) to allow remote connections is not an option. The solution that I am hoping to use is to install a web page (.aspx) on the same machine as the database and use my windows service installed on another machine to send web requests to the web page, and get a specific web response.

 

This is the code that I would be using to sending the request and retrieving the response:

WebRequest wRequest;
       WebResponse  wResponse;
       System.IO.StreamReader sReader;

       wRequest = System.Net.HttpWebRequest.Create("http://127.0.0.1/WebMonitor/Monitor.aspx");
       wRequest.Method = "GET";
       wResponse = wRequest.GetResponse();

       sReader = new System.IO.StreamReader(wResponse.GetResponseStream());
       String result;
       result = sReader.ReadToEnd().Trim();
       sReader.Close();

 

The problem that I am having is that I am unable to find any information on providing my own specific response from the web page. The value that I need to send back is a float. Any suggestions on how I can do this?

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Web service

 

I think a web service would be much more suitable than a web page, as it can expose methods which take strongly typed parameters and have strongly typed return values. Web service methods are also easier to invoke that plain web pages.

 

Your web service code would look something like this:

 

using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

public class MyWebService : WebService
{
   [WebMethod()]
   public float MonitorDatabase()
   {
       //Do action

       return someValue;
   }
}

 

In the windows service project, you can then add a web reference to this web service, and use it like any other class:

 

MyWebService serv = new MyWebService();

retVal = serv.MonitorDatabase();

 

Good luck :)

Never trouble another for what you can do for yourself.
Posted

Re: Web service

 

Have previously used web services with windows services, however I ran in the problems, in that the windows service seems to have lost its reference to the web service. Don't particularly want to get caught out again a second time. Is there a simple way of supplying a web references, without right clicking on references and going "add web reference"?

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

  • 1 month later...
Posted
I believe that when you add the web ref that way in studio it actually dumps something in the web.config file with the url. But i don't know if something gets compiled as well which would mean that you could not redirect the url after you have deployed. I have also experienced times when the web ref seems to have been 'lost'. Also don't forget that you need to refresh it if you change the web method code. I think when you set the ref through studio alot of things happen so i would stick with that way of doing it. You want that proxy to be created for you, it gives you intellinonsense when working with the web service.
Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...