tags:

views:

67

answers:

2

I have a Windows Service which I need to have installed on a machine and run just long enough to send out an email of logs and then sleep for 24 hours. If I call the service method from a web client, it works fine, but when I call it from the windows service, it fails every time and the error information doesn't give me anything specific to investigate:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.

 public partial class EDBDailyLogMailer : ServiceBase
 {
    Thread thread;

    public EDBDailyLogMailer()
    {
        InitializeComponent();
        this.ServiceName = "EDB Daily Log Mailer";
    }

    protected override void OnStart(string[] args)
    {
        try
        {
            thread = new Thread(MailLogDaily);
            thread.Start();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    static void MailLogDaily()
    {
        while (true)   
        {
            try
            {
                using (ApprovableFieldClient client = new ApprovableFieldClient())
                    client.EmailEventLog();
                Thread.Sleep(86400000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

The code in EmailEventLog() works fine when called from other places, so I won't post that code. Here's my endpoint in the App.config:

 <system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="ExperienceServiceBinding" maxReceivedMessageSize="1048576" maxBufferSize="1048576"/>
  </netTcpBinding>
</bindings>
<client>
  <endpoint bindingConfiguration="ExperienceServiceBinding" address="net.tcp://bosvc01:1125/ApprovableFieldService" binding="netTcpBinding" contract="Ropes.Experience.Administration.Contracts.Services.IApprovableFieldService">
    <identity>
      <servicePrincipalName value="[email protected]"/>
    </identity>
  </endpoint>
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="Ropes.Experience.Administration.Managers.ApprovableFieldManagerBehavior">
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

The service for ApprovableFieldClient is being hosted on bosvc01:1125

Any suggestions would be greatly appreciated. Thank you.

A: 

You're possibly having a problem because of the using block around your client proxy object. See this article: http://msdn.microsoft.com/en-us/library/aa355056.aspx

The call to dispose of your client proxy object might be masking the underlying exception.

Dr. Wily's Apprentice
+1  A: 

Solved. I removed all my try/catches and was given more description information in the error message

Jesse Roper