[RESOLVED] windows Service - missing listener
Ok,
This is a culmination of my other post's regarding WCF being hosted by a windows service.
I've noticed that from the control panel if I get my windows service running then go to Task Manger/processes. My process can be seen and it gives me a PID let's say it's 2212.
Now if I go to a command prompt and type netstat -oan there is nothing listed for PID 2212 suggesting that there is no listener on my Windows Service, which might explain why I cannot reference the service. So back in my Windows Service App (VS2010). How do I add a listener?
Re: windows Service - missing listener
Ok, in my windows service I have referenced a listener, now how do I set my WCF Method against the listener?? I.e. what goes after declaring my Socket in ListenerThread() ??
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceProcess;
using System.Text;
using wcfBorderauxIRSService;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace IRSBorderauxService
{
public partial class IRSBorderauxService : ServiceBase
{
internal static ServiceHost sHost = null;
private readonly int port = 8730;
private readonly IPAddress ip = IPAddress.Parse("127.0.0.1");
private TcpListener listener;
private Thread listenerThread;
BackgroundWorker worker;
public IRSBorderauxService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
listenerThread = new Thread(ListenerThread);
listenerThread.IsBackground = true;
listenerThread.Name = "IRSListener";
listenerThread.Start();
}
protected override void OnStop()
{
if (sHost != null)
{
sHost.Close();
sHost = null;
EventLog.WriteEntry("IRSBorderauxService Stopping", System.Diagnostics.EventLogEntryType.Information);
}
if (listener != null) { this.listener.Stop(); }
}
protected void worker_DoWork(object sender, DoWorkEventArgs e)
{
sHost = new ServiceHost(typeof(wcfBorderauxIRSService.IRSService));
sHost.Open();
ServiceEndpoint endpoint = sHost.Description.Endpoints[0];
EventLog.WriteEntry(endpoint.Contract.Name + " Started" + " listening on " + endpoint.Address + " (" + endpoint.Binding.Name + ")",
System.Diagnostics.EventLogEntryType.Information);
}
protected void ListenerThread()
{
try
{
this.listener = new TcpListener(this.ip, this.port);
this.listener.Start();
while (true)
{
Socket clientSocket = listener.AcceptSocket();
?????????????? }
}
catch (SocketException ex)
{
Trace.TraceError("IRSBorderauxService Error ", ex.Message);
}
}
}
}