Thread abort exception from windows service when call WCF service method RRS feed

  • Question

  • I have one windows service, which is invoked using commandline client C# application. The functionality of windows service is to execute some Batch jobs. In one of the Batch job, it calls an email service (WCF service) and send mail based on the values passed. It has one operation contract 'SendMail' with the signature as 'SendMail(object[][] parameters, string[] recipients)'. 

    I am getting 'Thread was being aborted exception' after all the mails have been sent. But when I call the email service from console application, I did not receive any exception. I tried changes in configuration to increase timeout, but still the exception is occurring. I checked solution in the net, but I could not solve my problem yet. Can anyone have idea about the reason for this exception. Thanks in advance. 

    The following is the stack trace of the exception which I received.

    Exception in sendmail : Thread was being aborted. 
    Trace :    at System.Net.ConnectStream.WriteHeaders(Boolean async)
       at System.Net.HttpWebRequest.EndSubmitRequest()
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at SampleBatchJob.EmailServiceRef.IService.SendMail(Object[][] parameters, String[] recipients)
       at SampleBatchJob.EmailServiceRef.ServiceClient.SendMail(Object[][] parameters, String[] recipients) in c:\Projects\BatchFramework\Arivazhagi\ACA.Batch5.0WC\Samples\SampleBatchJob\Service References\EmailServiceRef\Reference.cs:line 62
       at Avanade.ACA.Batch.Batch.SampleBatchJob.EmailBatchJob.Execute(JobExecutionContext context) in c:\Projects\BatchFramework\Arivazhagi\ACA.Batch5.0WC\Samples\SampleBatchJob\EmailBatchJob.cs:line 71



    Sunday, November 17, 2013 5:28 AM


  • Hi JMukunth,

    So the error occurs when your windows service trying to invoke a WCF service operation (for sending email), correct?

    If so, is the service using any particular security authentication settings? Since when using console app to invoke service, it runs under your current logon user account, while running with windows service, it runs under service account. In addition, you can use fiddler or other HTTP debugger tool to inspect the request/response of the WCF service operation call (when invoked from console and windows service app) to see if there is any difference.

    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, November 18, 2013 8:52 AM