Hi All,
I originally wrote a standard c#4.0 web app, however because the client was designed essentially to run a batch process I was receiving time out issues because the batch process can take anything up to a couple of hours. I moved the long running process out to a WCF Service Library, but because just leaving it there would leave the potential for time out issues under IIS I created a windows Service Wrapper to the WCF Service.I still seem to be having time out issues because everything wants to run Async when really I want to run Syncronously such that once I have called my windows service method from the client I want the process to continue in the background and I dont care that the client may close their browser or even turn their machine off. So to show some code:
Initially In my windows server I was using a background worked, but that was specifically designed for Async, so I changed to a normal 'Create new Thread' method, but that's still the same, I've been looking at some of the new features in.net 4.0 such as tasks etc, but they all assume that the parent thread is still running and if that is destroyed then so do these (that said when my code runs, that's not quite true).
so first off, in my WCF Service I have just 1 method on the interface:
Code:
[ServiceContract]
public interfaceIRS
{
[OperationContract(IsOneWay=true)]
void ProcessBorderaux();
and in the declaration to the service class I have adorned a ServiceBehaviour:
Code:
[ServiceBehavior(AutomaticSessionShutdown = false, UseSynchronizationContext = false, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public classIRSService : IRS
{
No up a level to my windows Service in my OnStart event:
Code:
protected override void OnStart(string[] args)
{
Thread t = newThread(newThreadStart(RunService));
try
{
t.TrySetApartmentState(ApartmentState.STA);
t.Start();
}
catch
{
if (t.IsAlive) { t.Abort(); }
throw;
}
}
and the RunService :
Code:
protected void RunService()
{
sHost = newServiceHost(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);
}
then up in my client:
Code:
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static String Process(String Irs,String other)
{
..........
using (IRSService.RSClient WCF = new RSClient())
{
WCF.ProcessBorderaux();
}
.......
Now what happens is the process runs no problem, but i receive a socket time out on the closing } of my using statement in the client. If at this point I stop my client process, the windows/wcf service continues to run, so closing my client browser and stopingthe local web server (running in debug), doesn't kill the server process :). So how do I force the windows service to return as soon as ProcessBorderaux in the WCF Library has been initiated? I was going to do a crafty and say that when it times out I dont care about the error because the batch process has been initiated and is running, but it doesn't matter weather I place a try catch block arounf the Using statement or inside, it doesn't catch the error.