J
jwpaco
I am new to services and I have quite the task. I need a windows
service that will, once started, open a socket and listen for client
connections. When a connection is made, the client will want the
service to query the db and return a value. This is for use with an IVR
system. Basically, a customer will callin and request some account
information and the service will need to qoery the db and return an
answer to the customer through the IVR system. I have started the
project but I am not getting anywhere fast. I an not even sure I am on
the right path. I thought of using web services, but that is not an
option because the machine this will be installed on will not have IIS
and it cannot be installed. I will paste my code below. Any help is
appreciated.
Justin
<code>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MyIVR
{
public partial class svcTCP : ServiceBase
{
private readonly int port = 45000;
private readonly IPAddress ip = IPAddress.Parse("127.0.0.1");
private TcpListener listener;
public svcTCP()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("IVRSource"))
{
System.Diagnostics.EventLog.CreateEventSource("IVRSource", "IVRLog");
}
eventLog1.Source = "IVRSource";
eventLog1.Log = "IVRLog";
}
protected override void OnStart(string[] args)
{
svcTCP service = new svcTCP();
eventLog1.WriteEntry("Service Started.");
listener = new TcpListener(ip, port);
listener.Start();
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service Stopped.");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("Service Resumed.");
}
}
}
</code>
service that will, once started, open a socket and listen for client
connections. When a connection is made, the client will want the
service to query the db and return a value. This is for use with an IVR
system. Basically, a customer will callin and request some account
information and the service will need to qoery the db and return an
answer to the customer through the IVR system. I have started the
project but I am not getting anywhere fast. I an not even sure I am on
the right path. I thought of using web services, but that is not an
option because the machine this will be installed on will not have IIS
and it cannot be installed. I will paste my code below. Any help is
appreciated.
Justin
<code>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MyIVR
{
public partial class svcTCP : ServiceBase
{
private readonly int port = 45000;
private readonly IPAddress ip = IPAddress.Parse("127.0.0.1");
private TcpListener listener;
public svcTCP()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("IVRSource"))
{
System.Diagnostics.EventLog.CreateEventSource("IVRSource", "IVRLog");
}
eventLog1.Source = "IVRSource";
eventLog1.Log = "IVRLog";
}
protected override void OnStart(string[] args)
{
svcTCP service = new svcTCP();
eventLog1.WriteEntry("Service Started.");
listener = new TcpListener(ip, port);
listener.Start();
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service Stopped.");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("Service Resumed.");
}
}
}
</code>